Log
in package
Log
This is the primary logger for a Leaf application. You may provide a Log Writer in conjunction with this Log to write to various output destinations (e.g. a file). This class provides this interface:
debug( mixed $object, array $context ) info( mixed $object, array $context ) notice( mixed $object, array $context ) warning( mixed $object, array $context ) error( mixed $object, array $context ) critical( mixed $object, array $context ) alert( mixed $object, array $context ) emergency( mixed $object, array $context ) log( mixed $level, mixed $object, array $context )
This class assumes only that your Log Writer has a public write()
method
that accepts any object as its one and only argument. The Log Writer
class may write or send its argument anywhere: a file, STDERR,
a remote web API, etc. The possibilities are endless.
Tags
Table of Contents
Constants
Properties
Methods
- __construct() : mixed
- Constructor
- alert() : mixed|bool
- Log alert message
- critical() : mixed|bool
- Log critical message
- debug() : mixed|bool
- Log debug message
- emergency() : mixed|bool
- Log emergency message
- enabled() : bool|void
- Enable or disable logging/return logging state
- error() : mixed|bool
- Log error message
- getLevel() : mixed
- Get/Set log level
- info() : mixed|bool
- Log info message
- isEnabled() : bool
- Is logging enabled?
- level() : mixed
- Get/Set log level
- log() : mixed|bool
- Log message
- notice() : mixed|bool
- Log notice message
- warning() : mixed|bool
- Log warning message
- writer() : mixed
- Get/Set log writer
- interpolate() : string
- Interpolate log message
Constants
ALERT
public
mixed
ALERT
= 2
CRITICAL
public
mixed
CRITICAL
= 3
DEBUG
public
mixed
DEBUG
= 8
EMERGENCY
public
mixed
EMERGENCY
= 1
ERROR
public
mixed
ERROR
= 4
INFO
public
mixed
INFO
= 7
NOTICE
public
mixed
NOTICE
= 6
WARN
public
mixed
WARN
= 5
Properties
$enabled
protected
bool
$enabled
$level
protected
int
$level
$levels
protected
static array<string|int, mixed>
$levels
= [self::EMERGENCY => 'EMERGENCY', self::ALERT => 'ALERT', self::CRITICAL => 'CRITICAL', self::ERROR => 'ERROR', self::WARN => 'WARNING', self::NOTICE => 'NOTICE', self::INFO => 'INFO', self::DEBUG => 'DEBUG']
$writer
protected
mixed
$writer
Methods
__construct()
Constructor
public
__construct(mixed $writer) : mixed
Parameters
- $writer : mixed
alert()
Log alert message
public
alert(mixed $object[, array<string|int, mixed> $context = [] ]) : mixed|bool
Parameters
- $object : mixed
- $context : array<string|int, mixed> = []
Return values
mixed|bool —What the Logger returns, or false if Logger not set or not enabled
critical()
Log critical message
public
critical(mixed $object[, array<string|int, mixed> $context = [] ]) : mixed|bool
Parameters
- $object : mixed
- $context : array<string|int, mixed> = []
Return values
mixed|bool —What the Logger returns, or false if Logger not set or not enabled
debug()
Log debug message
public
debug(mixed $object[, array<string|int, mixed> $context = [] ]) : mixed|bool
Parameters
- $object : mixed
- $context : array<string|int, mixed> = []
Return values
mixed|bool —What the Logger returns, or false if Logger not set or not enabled
emergency()
Log emergency message
public
emergency(mixed $object[, array<string|int, mixed> $context = [] ]) : mixed|bool
Parameters
- $object : mixed
- $context : array<string|int, mixed> = []
Return values
mixed|bool —What the Logger returns, or false if Logger not set or not enabled
enabled()
Enable or disable logging/return logging state
public
enabled([bool|null $enabled = null ]) : bool|void
Parameters
- $enabled : bool|null = null
-
Whether to enable or disable logging
Return values
bool|voiderror()
Log error message
public
error(mixed $object[, array<string|int, mixed> $context = [] ]) : mixed|bool
Parameters
- $object : mixed
- $context : array<string|int, mixed> = []
Return values
mixed|bool —What the Logger returns, or false if Logger not set or not enabled
getLevel()
Get/Set log level
public
static getLevel(int|null $level) : mixed
Parameters
- $level : int|null
-
The log level
info()
Log info message
public
info(mixed $object[, array<string|int, mixed> $context = [] ]) : mixed|bool
Parameters
- $object : mixed
- $context : array<string|int, mixed> = []
Return values
mixed|bool —What the Logger returns, or false if Logger not set or not enabled
isEnabled()
Is logging enabled?
public
isEnabled() : bool
Return values
boollevel()
Get/Set log level
public
level([int|null $level = null ]) : mixed
Parameters
- $level : int|null = null
-
The log level
log()
Log message
public
log(mixed $level, mixed $object[, array<string|int, mixed> $context = [] ]) : mixed|bool
Parameters
- $level : mixed
- $object : mixed
- $context : array<string|int, mixed> = []
Tags
Return values
mixed|bool —What the Logger returns, or false if Logger not set or not enabled
notice()
Log notice message
public
notice(mixed $object[, array<string|int, mixed> $context = [] ]) : mixed|bool
Parameters
- $object : mixed
- $context : array<string|int, mixed> = []
Return values
mixed|bool —What the Logger returns, or false if Logger not set or not enabled
warning()
Log warning message
public
warning(mixed $object[, array<string|int, mixed> $context = [] ]) : mixed|bool
Parameters
- $object : mixed
- $context : array<string|int, mixed> = []
Return values
mixed|bool —What the Logger returns, or false if Logger not set or not enabled
writer()
Get/Set log writer
public
writer([mixed $writer = null ]) : mixed
Parameters
- $writer : mixed = null
interpolate()
Interpolate log message
protected
interpolate(mixed $message[, array<string|int, mixed> $context = [] ]) : string
Parameters
- $message : mixed
-
The log message
- $context : array<string|int, mixed> = []
-
An array of placeholder values
Return values
string —The processed string