Luminova Framework

PHP Luminova: HTTP Remote Logging

Last updated: 2026-11-28 20:57:12

Configure encrypted remote logging with a shared secret key and send application logs to a remote server using NovaLogger.

The Luminova\Logger\NovaLogger supports remote HTTP logging, allowing you to send critical logs to a server over the internet.

You can trigger remote logging in three ways:

  1. Automatically, if remote logging is enabled in your .env file.
  2. By calling the remote() method on the NovaLogger class.
  3. By calling the dispatch() method on the Luminova\Logger\Logger class.

Remote logs are sent as an HTTP POST request with a JSON payload, which can be encrypted or unencrypted.

The server receiving the logs must respond quickly and should not block, even if it cannot store the log.


Remote Logging Configuration

To automatically send critical logs to a remote server, set the endpoint in your .env file:

# /.env
logger.remote.logs = https://example.com/api/logs/ingest

This tells NovaLogger where to send your logs whenever a critical event occurs.


Encrypted Log Payload

NovaLogger can send logs encrypted for security. To enable encryption, define a shared secret key in your .env file using logger.remote.sign.key or its fallback, logger.remote.shared.key. Configure the same secret on the receiver.

If the key is not set, logs will be sent in plain JSON.

# /.env
logger.remote.sign.key = YOUR_SHARED_SECRET

Structure of an Encrypted Request

The sender wraps the encoded OpenSSL payload in one JSON field:

{
  "data": "BASE64_ENCODED_PAYLOAD"
}

The field contains a base64-encoded JSON envelope with the driver, cipher, nonce, ciphertext, and authentication tag. Pass the complete data string to the Luminova OpenSSL driver. The receiver needs the same shared key and key-derivation configuration as the sender.


Log Payload

A raw log is sent as a JSON object with all relevant information about the event. Example:

{
  "app": "Luminova",
  "host": "api.example.com",
  "version": "Luminova",
  "message": "User authentication failed",
  "context": {
    "user_id": 42,
    "role": "admin"
  },
  "tracer": [],
  "level": "error",
  "name": "AppLogger",
  "ipaddress": "192.168.1.10",
  "url": "https://api.example.com/login",
  "referer": "https://example.com",
  "method": "POST",
  "env": "HTTP",
  "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)"
}

Field Description:

This structure ensures that every log contains enough information to debug, trace, or monitor events effectively.

FieldTypeDescription
appstringThe application name sending the log.
hoststringThe server hostname or domain where the log originated.
versionstringCurrently populated from the application name.
messagestringA short description of the log event.
contextobject or arrayAdditional structured data relevant to the log (e.g., user ID, role).
levelstringLog severity (error, warning, info, etc.).
namestringLogger name or category generating the log.
ipaddressstringIP address of the client making the request.
urlstringFull URL that triggered the log.
refererstringThe referring URL (if available).
methodstringHTTP method used for the request (e.g., GET, POST).
agentstringUser-Agent string from the client making the request.
tracerarray or objectTrace data supplied to the logger.
envstringHTTP or CLI.

CLI logs include script, command, args, and php in place of the HTTP request fields.


Remote Server Handling

Receiver Behavior

Return a 2xx response after accepting the log. NovaLogger treats a 2xx response as success before inspecting the JSON body. For rejected payloads, return a non-2xx response and include an error description for diagnostics.

PHP Receivers

Use the receiver examples in a bootstrapped application. Replace the storage comment with your file, database, or queue write before returning success.

Encrypted Log Receiver

use Luminova\Security\Encryption\Driver\Openssl;

header('Content-Type: application/json');
$body = file_get_contents('php://input');
$input = is_string($body) ? json_decode($body, true) : null;
$key = getenv('LOG_SHARED_SECRET');

try {
    if (!is_array($input) || !is_string($input['data'] ?? null) || !$key) {
        throw new RuntimeException('Missing log payload or receiver key.');
    }

    $plaintext = (new Openssl($key, 'aes-256-gcm'))
        ->setData($input['data'])
        ->decrypt();

    $log = json_decode($plaintext, true, flags: JSON_THROW_ON_ERROR);
    if (!is_array($log) || !is_string($log['message'] ?? null)) {
        throw new RuntimeException('Invalid log payload.');
    }

    // Store or enqueue $log here.
    echo json_encode(['ok' => true]);
} catch (Throwable) {
    http_response_code(422);
    echo json_encode(['ok' => false, 'description' => 'Invalid log payload']);
}

Raw Log Receiver

This example shows how to receive plain JSON logs:

// https://example.com/api/logs/ingest.php

// 1. Read the raw JSON payload
header('Content-Type: application/json');
$body = file_get_contents('php://input');
$data = is_string($body) ? json_decode($body, true) : null;

// 2. Validate the payload
if (!is_array($data) || !is_string($data['message'] ?? null)) {
    http_response_code(422);
    echo json_encode([
        'ok' => false,
        'description' => 'Invalid log payload' // Inform client if payload is bad
    ]);
    exit;
}

// 3. Store the log as needed (database, file, queue, etc.)

// 4. Return success
echo json_encode(['ok' => true]);

Notes:

  • The server must always return HTTP 200, even on failure.
  • Invalid payloads are stored locally if necessary.

Success Response

Return HTTP 200 after storing or enqueuing the log. A JSON acknowledgement may include ok: true.

{
  "ok": true
}

Failure Response

Return a non-2xx response for a failure. If the HTTP client makes the response body available, NovaLogger can read description for the local log.

{
  "ok": false,
  "description": "Invalid payload"
}

Notes:

  • Response fields are for diagnostics only.
  • Use ok: false in the failure response body.

Response Context

When remote logging fails, the server can return additional context.NovaLogger can include this context in the local log when the HTTP client exposes the response body.

Example:

{
    "ok": false,
    "context": {
        "timestamp": "2026-01-14T03:00:00Z",
        "log_id": "abc123xyz"
    }
}
FieldDescription
log_idA unique ID assigned to each log. Useful for tracing and debugging specific logs.
timestampThe time the server processed the log. Helps correlate logs between client and server.

Including this context is optional but highly recommended for troubleshooting remote logging issues.