Logger
extends AbstractLogger
in package
Logger is an implementation of the PSR-3 Logger Interface.
This logger wraps \jLog with a log level.
Tags
Table of Contents
Constants
- DefaultLevel = \Psr\Log\LogLevel::ERROR
- The default log level: error.
- LogLevels = array(\Psr\Log\LogLevel::EMERGENCY, \Psr\Log\LogLevel::ALERT, \Psr\Log\LogLevel::CRITICAL, \Psr\Log\LogLevel::ERROR, \Psr\Log\LogLevel::WARNING, \Psr\Log\LogLevel::NOTICE, \Psr\Log\LogLevel::INFO, \Psr\Log\LogLevel::DEBUG)
- Levels ordered from most important to least important as defined in RFC 5424.
Properties
- $level : string
- The minimum logging level at which this logger will be used.
Methods
- __construct() : mixed
- Initialise the logger with a log level.
- getLevel() : string
- Get log level.
- isLevelHighEnough() : bool
- Check if the given level is high enough to be logged.
- log() : void
- Logs with an arbitrary level.
- setLevel() : void
- Set log level.
- interpolate() : string
- Interpolates context values into message placeholders according to PSR-3 rules.
Constants
DefaultLevel
The default log level: error.
public
string
DefaultLevel
= \Psr\Log\LogLevel::ERROR
LogLevels
Levels ordered from most important to least important as defined in RFC 5424.
public
array<string|int, string>
LogLevels
= array(\Psr\Log\LogLevel::EMERGENCY, \Psr\Log\LogLevel::ALERT, \Psr\Log\LogLevel::CRITICAL, \Psr\Log\LogLevel::ERROR, \Psr\Log\LogLevel::WARNING, \Psr\Log\LogLevel::NOTICE, \Psr\Log\LogLevel::INFO, \Psr\Log\LogLevel::DEBUG)
Tags
Properties
$level
The minimum logging level at which this logger will be used.
protected
string
$level
Methods
__construct()
Initialise the logger with a log level.
public
__construct([string $level = LogLevel::ERROR ]) : mixed
Parameters
- $level : string = LogLevel::ERROR
-
The minimum logging level at which this logger will be used
Tags
getLevel()
Get log level.
public
getLevel() : string
Return values
stringisLevelHighEnough()
Check if the given level is high enough to be logged.
public
isLevelHighEnough(string $level) : bool
This is used to avoid unnecessary logging. For example, if the logger is set to LogLevel::ERROR, then LogLevel::INFO will not be logged. But LogLevel::ERROR will be logged. if the level is not in the list of LogLevels, it will be considered as not high enough.
Parameters
- $level : string
Return values
boollog()
Logs with an arbitrary level.
public
log(mixed $level, string|Stringable $message[, array<string|int, mixed> $context = array() ]) : void
Parameters
- $level : mixed
- $message : string|Stringable
- $context : array<string|int, mixed> = array()
Tags
setLevel()
Set log level.
public
setLevel(string $level) : void
Parameters
- $level : string
Tags
interpolate()
Interpolates context values into message placeholders according to PSR-3 rules.
private
interpolate(string $message[, array<string|int, mixed> $context = array() ]) : string
This method replaces placeholders in the message with actual values from the context array.
Parameters
- $message : string
-
Message with placeholders
- $context : array<string|int, mixed> = array()
-
Values to replace placeholders
Tags
Return values
string —Interpolated message