Luminova Framework

PHP Luminova: PSR Aware Logger for Custom Application Logging

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

Inject a PSR-3 logger into an application class so logging can be configured by its caller.

The LoggerAware class implements the PSR LoggerAwareInterface from the PSR-3 logging standard. It provides a mechanism for classes to accept and utilize a PSR-compliant logger instance, enabling seamless logging.

This design allows easy swapping of logging implementations and ensures compatibility with any PSR-compliant logger, enhancing flexibility and standardization.

The primary method in LoggerAware is setLogger, which injects a logger instance into the implementing class.

Primary Benefits:

  • Flexibility: Easily switch between different logging implementations.
  • Standards Compliance: Fully compatible with any PSR-compliant logger.

Using a PSR Logger in Application Code

Accept a LoggerInterface in your class constructor. This works with NovaLogger or a configured Monolog instance.

use Luminova\Logger\NovaLogger;
use Psr\Log\LoggerInterface;

final class ReportService
{
    public function __construct(private LoggerInterface $logger)
    {
    }

    public function markReady(int $reportId): void
    {
        $this->logger->info('Report is ready.', ['report_id' => $reportId]);
    }
}

$service = new ReportService(new NovaLogger('reports'));
$service->markReady(42);

For email or remote delivery, call the corresponding methods on NovaLogger.


Class Definition


Properties

logger

The PSR logger interface class instance.

protected ?Psr\Log\LoggerInterface $logger = null;

Methods

constructor

Initialize Aware Logger Interface.

public function __construct(?LoggerInterface $logger = null)

Parameters:

ParameterTypeDescription
$logger?LoggerInterfaceThe logger instance (default null).

setLogger

Set a logger instance on the object.

public function setLogger(LoggerInterface $logger)

Parameters:

ParameterTypeDescription
$logger\Psr\Log\LoggerInterfaceThe logger instance.

getLogger

Get the instance of PSR logger class.

public function getLogger(): ?LoggerInterface

Return:

LoggerInterface|null - Return instance of logger class inuse.


emergency

Log an emergency message.

public function emergency($message, array $context = array())

Parameters:

ParameterTypeDescription
$messagestringThe emergency message to log.
$contextarray<array-key, mixed>Additional context data (optional).

alert

Log an alert message.

public function alert($message, array $context = array())

Parameters:

ParameterTypeDescription
$messagestringThe alert message to log.
$contextarray<array-key, mixed>Additional context data (optional).

critical

Log a critical message.

public function critical($message, array $context = array())

Parameters:

ParameterTypeDescription
$messagestringThe critical message to log.
$contextarray<array-key, mixed>Additional context data (optional).

error

Log an error message.

public function error($message, array $context = array())

Parameters:

ParameterTypeDescription
$messagestringThe error message to log.
$contextarray<array-key, mixed>Additional context data (optional).

warning

Log a warning message.

public function warning($message, array $context = array())

Parameters:

ParameterTypeDescription
$messagestringThe warning message to log.
$contextarray<array-key, mixed>Additional context data (optional).

notice

Log a notice message.

public function notice($message, array $context = array())

Parameters:

ParameterTypeDescription
$messagestringThe notice message to log.
$contextarray<array-key, mixed>Additional context data (optional).

info

Log an info message.

public function info($message, array $context = array())

Parameters:

ParameterTypeDescription
$messagestringThe info message to log.
$contextarray<array-key, mixed>Additional context data (optional).

debug

Log a debug message.

public function debug($message, array $context = array())

Parameters:

ParameterTypeDescription
$messagestringThe debug message to log.
$contextarray<array-key, mixed>Additional context data (optional).

exception

Log an exception message.

public function exception(Throwable|string $message, array $context = []): void

Parameters:

ParameterTypeDescription
$messageThrowable&#124;stringThe exception message to log.
$contextarray<string&#124;int,mixed>Additional context data (optional).

php

Log an php message.

public function php(string $message, array $context = []): void

Parameters:

ParameterTypeDescription
$messagestringThe php message to log.
$contextarray<string&#124;int,mixed>Additional context data (optional).

metrics

Log an performance metric.

public function metrics(string $data, array $context = []): void

Parameters:

ParameterTypeDescription
$datastringThe php message to log.
$contextarray<string&#124;int,mixed>Additional context data (optional).

log

Log a message at a specified log level.

public function log($level, $message, array $context = []): void

Parameters:

ParameterTypeDescription
$levelstringThe log level (e.g., emergency, error, info).
$messagestringThe log message.
$contextarray<array-key, mixed>Additional context data (optional).

Throws: