Logger
extends AbstractLogger
in package
implements
LoggerInterface
Kotchasan Logger Class (PSR-3)
Tags
Interfaces, Classes and Traits
- LoggerInterface
- Describes a logger instance.
Table of Contents
- $instance : Singleton
- Singleton instance
- $logLevels : array<string|int, mixed>
- Log Levels
- $options : array<string|int, mixed>
- Log options
- alert() : mixed
- Action must be taken immediately
- create() : static
- Create a Logger instance (Singleton).
- critical() : mixed
- Critical conditions
- debug() : mixed
- Detailed debug information
- emergency() : mixed
- System is unusable
- error() : mixed
- Runtime errors that do not require immediate action but should typically be logged and monitored
- info() : mixed
- Interesting events
- log() : void
- Logs a message with an arbitrary level.
- notice() : mixed
- Normal but significant events
- warning() : mixed
- Exceptional occurrences that are not errors
- __construct() : mixed
- Private constructor.
Properties
$instance
Singleton instance
protected
static Singleton
$instance
= null
$logLevels
Log Levels
protected
array<string|int, mixed>
$logLevels
= [PsrLogLogLevel::EMERGENCY => 0, PsrLogLogLevel::ALERT => 1, PsrLogLogLevel::CRITICAL => 2, PsrLogLogLevel::ERROR => 3, PsrLogLogLevel::WARNING => 4, PsrLogLogLevel::NOTICE => 5, PsrLogLogLevel::INFO => 6, PsrLogLogLevel::DEBUG => 7]
$options
Log options
protected
array<string|int, mixed>
$options
= ['dateFormat' => 'Y-m-d H:i:s', 'logFormat' => '[{datetime}] {level}: {message} {context}', 'logFilePath' => 'logs/', 'extension' => 'php']
Methods
alert()
Action must be taken immediately
public
alert(string $message[, array<string|int, mixed> $context = [] ]) : mixed
Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up
Parameters
- $message : string
- $context : array<string|int, mixed> = []
Return values
mixed —create()
Create a Logger instance (Singleton).
public
static create([array<string|int, mixed> $options = [] ]) : static
Parameters
- $options : array<string|int, mixed> = []
-
Log options (optional).
Return values
static —critical()
Critical conditions
public
critical(string $message[, array<string|int, mixed> $context = [] ]) : mixed
Example: Application component unavailable, unexpected exception
Parameters
- $message : string
- $context : array<string|int, mixed> = []
Return values
mixed —debug()
Detailed debug information
public
debug(string $message[, array<string|int, mixed> $context = [] ]) : mixed
Parameters
- $message : string
- $context : array<string|int, mixed> = []
Return values
mixed —emergency()
System is unusable
public
emergency(string $message[, array<string|int, mixed> $context = [] ]) : mixed
Parameters
- $message : string
- $context : array<string|int, mixed> = []
Return values
mixed —error()
Runtime errors that do not require immediate action but should typically be logged and monitored
public
error(string $message[, array<string|int, mixed> $context = [] ]) : mixed
Parameters
- $message : string
- $context : array<string|int, mixed> = []
Return values
mixed —info()
Interesting events
public
info(string $message[, array<string|int, mixed> $context = [] ]) : mixed
Example: User logs in, SQL logs
Parameters
- $message : string
- $context : array<string|int, mixed> = []
Return values
mixed —log()
Logs a message with an arbitrary level.
public
log(mixed $level, string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
- $level : mixed
-
The log level.
- $message : string
-
The log message.
- $context : array<string|int, mixed> = []
-
The log context (optional).
Return values
void —notice()
Normal but significant events
public
notice(string $message[, array<string|int, mixed> $context = [] ]) : mixed
Parameters
- $message : string
- $context : array<string|int, mixed> = []
Return values
mixed —warning()
Exceptional occurrences that are not errors
public
warning(string $message[, array<string|int, mixed> $context = [] ]) : mixed
Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong
Parameters
- $message : string
- $context : array<string|int, mixed> = []
Return values
mixed —__construct()
Private constructor.
private
__construct(array<string|int, mixed> $options) : mixed
Parameters
- $options : array<string|int, mixed>
-
Log options.