ConsoleLogger
extends Logger
in package
Represents a logger for logging messages to the console.
This class extends the abstract Logger class and provides functionality to log messages to the console.
Table of Contents
Constants
Properties
- $_device : mixed
- The name of the log file.
- $_maxLogLevel : int
- The maximum log level.
Methods
- __construct() : mixed
- Constructor.
- __get() : mixed
- Getter method.
- alert() : void
- Action must be taken immediately.
- Close() : void
- Closes the log file (not applicable for ConsoleLogger).
- Content() : mixed
- Retrieves the content of the log file (not applicable for ConsoleLogger).
- Create() : Logger
- Creates a logger instance based on the provided configuration.
- critical() : void
- Critical conditions.
- debug() : void
- Detailed debug information.
- DispatchEvent() : object|null
- Dispatches an event.
- emergency() : void
- System is unusable.
- error() : void
- Runtime errors that do not require immediate action but should typically be logged and monitored.
- HandleEvent() : self
- Adds an event handler.
- info() : void
- Interesting events.
- log() : void
- Logs with an arbitrary level.
- notice() : void
- Normal but significant events.
- Open() : void
- Opens the log file for sequential reading (not applicable for ConsoleLogger).
- Read() : array<string|int, mixed>
- Reads the last messages in the log starting from the last read position, returning them as an array of strings (not applicable for ConsoleLogger).
- RemoveHandler() : self
- Removes an event handler.
- warning() : void
- Exceptional occurrences that are not errors.
- WriteLine() : void
- Writes a log line to the console.
Constants
Alert
public
int
Alert
= 1
Alert level constant.
Critical
public
int
Critical
= 2
Critical level constant.
Debug
public
int
Debug
= 7
Debug level constant.
Emergency
public
int
Emergency
= 0
Emergency level constant.
Error
public
int
Error
= 3
Error level constant.
Informational
public
int
Informational
= 6
Informational level constant.
Notice
public
int
Notice
= 5
Notice level constant.
Warning
public
int
Warning
= 4
Warning level constant.
Properties
$_device
The name of the log file.
protected
mixed
$_device
$_maxLogLevel
The maximum log level.
protected
int
$_maxLogLevel
= 7
Methods
__construct()
Constructor.
public
__construct([int $maxLogLevel = 7 ][, mixed $dummy = '' ]) : mixed
Parameters
- $maxLogLevel : int = 7
-
The maximum log level.
- $dummy : mixed = ''
-
Dummy parameter (not used).
__get()
Getter method.
public
__get(string $prop) : mixed
Parameters
- $prop : string
-
The property name.
Return values
mixed —The value of the property.
alert()
Action must be taken immediately.
public
alert(string $message[, array<string|int, mixed> $context = array() ]) : void
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> = array()
Close()
Closes the log file (not applicable for ConsoleLogger).
public
Close() : void
Content()
Retrieves the content of the log file (not applicable for ConsoleLogger).
public
Content() : mixed
Return values
mixed —The content of the log file.
Create()
Creates a logger instance based on the provided configuration.
public
static Create(Config|array<string|int, mixed> $loggerConfig) : Logger
Parameters
- $loggerConfig : Config|array<string|int, mixed>
-
The logger configuration.
Tags
Return values
Logger —The logger instance.
critical()
Critical conditions.
public
critical(string $message[, array<string|int, mixed> $context = array() ]) : void
Example: Application component unavailable, unexpected exception.
Parameters
- $message : string
- $context : array<string|int, mixed> = array()
debug()
Detailed debug information.
public
debug(string $message[, array<string|int, mixed> $context = array() ]) : void
Parameters
- $message : string
- $context : array<string|int, mixed> = array()
DispatchEvent()
Dispatches an event.
public
DispatchEvent(string|Event $event[, mixed $args = null ][, bool $async = false ]) : object|null
Parameters
- $event : string|Event
-
The event object or its name.
- $args : mixed = null
-
Additional arguments to pass to the event handlers.
- $async : bool = false
-
Whether to dispatch the event asynchronously.
Return values
object|null —The event object with updated arguments, or null if the event does not exist.
emergency()
System is unusable.
public
emergency(string $message[, array<string|int, mixed> $context = array() ]) : void
Parameters
- $message : string
- $context : array<string|int, mixed> = array()
Tags
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 = array() ]) : void
Parameters
- $message : string
- $context : array<string|int, mixed> = array()
HandleEvent()
Adds an event handler.
public
HandleEvent(array<string|int, mixed>|string $ename, mixed $listener) : self
Parameters
- $ename : array<string|int, mixed>|string
-
The event name or an array of event names.
- $listener : mixed
-
The event handler.
Return values
selfinfo()
Interesting events.
public
info(string $message[, array<string|int, mixed> $context = array() ]) : void
Example: User logs in, SQL logs.
Parameters
- $message : string
- $context : array<string|int, mixed> = array()
log()
Logs with an arbitrary level.
public
log(mixed $level, string $message[, array<string|int, mixed> $context = array() ]) : void
Parameters
- $level : mixed
- $message : string
- $context : array<string|int, mixed> = array()
notice()
Normal but significant events.
public
notice(string $message[, array<string|int, mixed> $context = array() ]) : void
Parameters
- $message : string
- $context : array<string|int, mixed> = array()
Open()
Opens the log file for sequential reading (not applicable for ConsoleLogger).
public
Open([int $position = 0 ]) : void
Parameters
- $position : int = 0
-
The start position for reading.
Tags
Read()
Reads the last messages in the log starting from the last read position, returning them as an array of strings (not applicable for ConsoleLogger).
public
Read() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of log message strings.
RemoveHandler()
Removes an event handler.
public
RemoveHandler(string $ename, mixed $listener) : self
Parameters
- $ename : string
-
The event name.
- $listener : mixed
-
The event handler to remove.
Return values
selfwarning()
Exceptional occurrences that are not errors.
public
warning(string $message[, array<string|int, mixed> $context = array() ]) : void
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> = array()
WriteLine()
Writes a log line to the console.
public
WriteLine(int $level, mixed $data) : void
Parameters
- $level : int
-
The log level.
- $data : mixed
-
The log data.