Luminova Framework

PHP Luminova: Log Levels in the Logging System

Last updated: 2026-01-12 08:22:56

Defines standard and custom log levels used to categorize and manage log messages by severity.

The LogLevel class in Luminova defines a set of constants that represent logging severity levels. It follows common logging standards and supports both PSR-style string levels (such as 'error', 'info') and RFC 5424 numeric levels (0–7).

These constants provide a consistent and reliable way to classify log messages based on their importance and urgency.


Use Cases

  • Organize log messages by severity.
  • Ensure consistent log handling across different systems.
  • Filter or extend logs for debugging, error tracking, or performance monitoring.

Key Highlights

  • Standard Log Levels: Common levels such as EMERGENCY, ALERT, CRITICAL, ERROR, WARNING, INFO, and DEBUG.
  • Custom Levels: Additional levels like PHP, EXCEPTION, and METRICS for framework and application-specific use cases.
  • RFC 5424 Support: Supports numeric severity levels (0–7) alongside string-based levels.
  • Critical Levels: Levels considered critical by isCritical, including EMERGENCY, ALERT, CRITICAL, and EXCEPTION.

Examples

Log a message with a specific level

use App\Utils\MyLogger;

(new MyLogger)->log(LogLevel::CRITICAL, 'This is a critical error');

Validate a log level

if (LogLevel::has('critical')) {
    echo 'Log level is valid.';
} else {
    echo 'Log level not recognized.';
}

Resolve level

$level = LogLevel::resolve('critical') // critical
$level = LogLevel::resolve(2) // critical
$level = LogLevel::resolve(10) // NULL

Check if a log level is critical

var_dump(LogLevel::isCritical(LogLevel::WARNING));   // false
var_dump(LogLevel::isCritical(LogLevel::CRITICAL)); // true
var_dump(LogLevel::isCritical(LogLevel::ALERT));    // true
var_dump(LogLevel::isCritical(LogLevel::DEBUG));    // false

Assert log level in a custom logger

namespace App\Utils;

use Psr\Log\LoggerInterface;

class MyLogger implements LoggerInterface
{
    public function log(string|int $level, string $message): void
    {
        LogLevel::assert($level, __METHOD__);
        echo sprintf("[%s] %s\n", strtoupper((string) $level), $message);
    }
}

Class Definition

  • Full namespace: Luminova\Logger\LogLevel
  • This class is marked as final and can't be subclassed

Constants

Log Level Constants

ConstantTypeValueDescription
EMERGENCYstringemergencySystem is unusable. Immediate action required.
ALERTstringalertCritical issue that needs immediate attention.
CRITICALstringcriticalSevere condition, such as a service or application failure.
ERRORstringerrorRuntime errors that need investigation.
WARNINGstringwarningPotential problems that are not yet critical.
NOTICEstringnoticeNormal but significant events worth noting.
INFOstringinfoGeneral information about application behavior.
DEBUGstringdebugDetailed diagnostic information for development.
EXCEPTIONstringexceptionUncaught exceptions or handled error scenarios.
PHPstringphp_errorNative PHP errors such as warnings and fatal errors.
METRICSstringmetricsPerformance and monitoring data (typically production use).

RFC 5424 Syslog Severity Levels

These numeric levels are a standard reference used by syslog and many logging systems.

LevelNameDescription
0EMERGENCYSystem is unusable
1ALERTImmediate action required
2CRITICALCritical failure
3ERRORError condition
4WARNINGWarning condition
5NOTICENormal but significant
6INFOInformational message
7DEBUGDebug-level message

LEVELS

List of all valid log levels.

public const array<string,string> LEVELS = [
    'emergency'     => self::EMERGENCY,
    'alert'         => self::ALERT,
    'critical'      => self::CRITICAL,
    'error'         => self::ERROR,
    'warning'       => self::WARNING,
    'notice'        => self::NOTICE,
    'info'          => self::INFO,
    'debug'         => self::DEBUG,
    'exception'     => self::EXCEPTION,
    'php_error'     => self::PHP,
    'php'           => self::PHP,
    'metrics'       => self::METRICS,
];

Methods

has

Checks if the given log level is valid.

Supports both PSR-style string levels (e.g., error, info) and RFC 5424 numeric levels (0–7).

public static has(string|int $level): bool

Parameters:

ParameterTypeDescription
$levelstring|intThe log level to validate.

Return Value:

bool - Returns true if the level exists, false otherwise.


resolve

Resolves the canonical value for a given log level.

Maps a PSR-style string level or RFC 5424 numeric level to its internal representation.

public static resolve(string|int $level): ?string

Parameters:

ParameterTypeDescription
$levelstring|intThe log level to parse.

Return Value:

bool - Return the canonical log level, or null if invalid.


assert

Asserts that the given log level is valid.

This function checks if the provided log level exists in the predefined set of log levels.If the level is invalid, it throws an InvalidArgumentException with a detailed error message.

public static assert(string|int $level, ?string $function = null): void

Parameters:

ParameterTypeDescription
$levelstring|intThe log level to validate (e.g., LogLevel::ERROR, LogLevel::INFO, LogLevel::DEBUG).
$functionstring|nullOptional. The name of the calling function for context in the error message.

Throws:

\Luminova\Exceptions\InvalidArgumentException - If the provided log level is not valid.


isCritical

Checks if a given log level is considered critical.

Critical levels represent severe issues that require immediate attention, such as system failures or security breaches.

The following log levels are considered critical:

  • emergency
  • alert
  • critical
  • exception
public static isCritical(string|int $level): bool

Parameters:

ParameterTypeDescription
$levelstring|intThe log level to check (e.g., LogLevel::ERROR, LogLevel::INFO, LogLevel::DEBUG).

Return Value:

bool - Returns true if the level is critical, otherwise false.