Luminova Framework

PHP Luminova: Logging System and Dynamic Context Configuration

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

Configure logging context, rotation, remote delivery, and email templates.

The Logger configuration class controls how the default Nova Logger behaves: request context, log file size limits, backups, remote delivery options, and the HTML template used for email log notifications.

To replace the default logger with another PSR-compliant logger, return it from App\Kernel::getLogger(). The static Luminova\Logger\Logger class resolves its logger from the kernel and falls back to NovaLogger when none is provided.


Class Definition

  • Full namespace: App\Config\Logger
  • File path: /app/Config/Logger.php
  • This configuration derives from Luminova\Base\AbstractConfig.
  • This class is final.

Properties

contextHeaderName

Specifies the name of a request header to look for when adding additional context to logs.

This is useful for identifying users or API clients by extracting a unique identifier (like X-User-ID or Authorization) from the request headers. If the header is present, its value is added to the log context under the key __{headerName}. The value is read from the request headers first, then from the server variables.

public static ?string $contextHeaderName = null;

Note: Request context is not added in CLI mode.


contextFieldName

Specifies the name of a field in the request body to include in the log context.

This allows you to capture identifying information (e.g., user_id, client_id) from the request payload and include it in your log entries automatically. The value is added to the log context under the key __{fieldName}.

public static ?string $contextFieldName = null;

Note: Request context is not added in CLI mode.


remoteAsyncLogging

Enables non-blocking background delivery of remote logs (remote server, Telegram and Slack).

When enabled, the request is sent from a background process instead of blocking the current execution. When disabled, the log is sent immediately, and if delivery fails the message is written to the local log file.

You can also set this value with the environment variable logger.remote.async, which takes priority over this property.

public static bool $remoteAsyncLogging = false;

Note: This feature is only supported for Luminova\Logger\NovaLogger. On some servers, curl may be disabled in CLI mode.


remoteSendContext

Determines whether log context data is included when sending logs to remote destinations (remote server, Telegram and Slack).

You can also set this value with the environment variable logger.remote.send.context, which takes priority over this property.

public static bool $remoteSendContext = false;

maxSize

Specify the maximum size (in bytes) for each log level file (e.g., 10485760 for 10 MB). A value of 0 disables the limit.

When the limit is reached, a backup of the log file is created if logger.create.backup or $autoBackup is set to true; otherwise, the log file is cleared. The size is checked periodically after writes, not on every write.

You can also set this value with the environment variable logger.max.size, which takes priority over this property.

public static int $maxSize = 0;

autoBackup

Indicate whether a backup of the log file should be created when the logger.max.size or $maxSize limit is reached.

Set to true to create a zip backup in the backups directory inside the log path and empty the current log file, false to empty the log file only. Backups run in a background process.

You can also set this value with the environment variable logger.create.backup, which takes priority over this property.

public static bool $autoBackup = false;

Methods

getEmailLogTemplate

Customize and generate an HTML email template for logging notifications.

This method is called when NovaLogger sends a log by email (see logger.mail.logs). If the method returns null or an empty string, the default email template will be used.

public static function getEmailLogTemplate(
    RequestInterface $request,
    AbstractLogger $logger,
    string $message,
    string $level,
    array $context
): ?string

Parameters:

ParameterTypeDescription
$requestRequestInterfaceThe HTTP request object containing information about the request.
$loggerAbstractLoggerThe logger instance handling the log entry.
$messagestringThe log message.
$levelstringThe log level (e.g., 'info', 'warning', 'error').
$contextarray<array-key, mixed>Additional context information for the log message.

Return:

string|null - Return a custom HTML email template or null/empty string to use the default template.

Note: $message is passed as raw text, so escape it with htmlspecialchars() before adding it to your HTML.

Example:

public static function getEmailLogTemplate(
    RequestInterface $request,
    AbstractLogger $logger,
    string $message,
    string $level,
    array $context
): ?string
{
    $message = htmlspecialchars($message);
    $url = htmlspecialchars($request->getUrl());
    $level = strtoupper($level);

    return "<h3>[{$level}] {$message}</h3><p>Request URL: {$url}</p>";
}