Logger
in package
Log class that is working on monolog.
Tags
Table of Contents
Properties
- $Config : Config
- $Container : Container
- $donotLogLevel : int
- $logEnabled : bool
- $logLevel : int
- $logLevelName : string
Methods
- __construct() : mixed
- Logger class constructor.
- write() : bool
- Write the message to log file.
- getLogger() : Logger|null
- Get Logger class with specified channel.
- setLogLevelNameAndNumber() : mixed
- Set log level name (readable such as debug, info, etc...) and number from `\Monolog\Logger::CONSTANT`.
Properties
$Config
protected
Config
$Config
$Container
protected
Container
$Container
$donotLogLevel
protected
int
$donotLogLevel
= 0
Do not log the level is UNDER selected. 0=debug (or log it ALL), 1=info, 2=notice, 3=warning, 4=error, 5=critical, 6=alert, 7=emergency
$logEnabled
protected
bool
$logEnabled
= false
Log enabled or not? true
= yes, false
= no.
$logLevel
protected
int
$logLevel
Log level from \Monolog\Logger::CONSTANT
.
$logLevelName
protected
string
$logLevelName
The log level as readable name such as debug, info, etc.
Methods
__construct()
Logger class constructor.
public
__construct(Container $Container[, array<string|int, mixed> $options = [] ]) : mixed
You can load this class via framework's Container
object named Logger
. Example: $Logger = $Container->get('Logger');
.
Parameters
- $Container : Container
-
The DI container class.
- $options : array<string|int, mixed> = []
-
The options that will be override config file. The options array keys must be the same as keys in side
log
inapp.php
config file. Example:['enable' => true, 'donotLogLevel' => 1]
.
write()
Write the message to log file.
public
write(string $channel, int $logLevel, string $message[, array<string|int, mixed> $context = [] ][, array<string|int, mixed> $options = [] ]) : bool
Parameters
- $channel : string
-
The channel such as 'security', 'db', or other. Leave blank to use default channel.
- $logLevel : int
-
The log level as integer. 0=debug, 1=info, 2=notice, 3=warning, 4=error, 5=critical, 6=alert, 7=emergency
- $message : string
-
The message that will be write to log file. See https://github.com/Seldaek/monolog/blob/master/doc/message-structure.md for more information.
- $context : array<string|int, mixed> = []
-
The array data that will be passed with the message or it can be just additional data.
- $options : array<string|int, mixed> = []
-
The options for this method in associative array. Available options:
dontLogProfiler
(bool).
Return values
bool —Return true
or false
wether the record has been processed.
getLogger()
Get Logger class with specified channel.
protected
getLogger(string $channel, int $logLevel) : Logger|null
If log level is lower than donotLogLevel
configuration then it will return null.
Parameters
- $channel : string
-
The channel name.
- $logLevel : int
-
The log level as integer. 0=debug, 1=info, 2=notice, 3=warning, 4=error, 5=critical, 6=alert, 7=emergency
Return values
Logger|null —Return Logger
object or null
.
setLogLevelNameAndNumber()
Set log level name (readable such as debug, info, etc...) and number from `\Monolog\Logger::CONSTANT`.
protected
setLogLevelNameAndNumber(int $logLevel) : mixed
Parameters
- $logLevel : int
-
The log level number.