Logger
in package
Table of Contents
Properties
- $logHelper : bool
- $color : bool
- $instance : Logger|null
- $logImportant : array<string|int, mixed>
- $logMethods : array<string|int, mixed>
- $logPath : string
Methods
- configure() : void
- Configures the logger with the provided settings.
- getInstance() : Logger
- Returns the singleton instance of the Logger class.
- getLogHelper() : bool
- Returns the current state of the log helper.
- log() : void
- Logs a message with specified level and backtrace information.
- logFormatter() : string
- Formats the log message with optional color coding.
- setColor() : void
- Enables or disables colored output in logs.
- setLogHelper() : void
- Enables or disables the log helper.
- setLogImportantLevels() : void
- Sets the log levels that are always outputted, even if the log helper is deactivated.
- setLogMethods() : void
- Sets the methods used for logging.
- setlogPathFolder() : void
- Sets the path where log files will be stored.
- writeLogMessage() : void
- Writes a log message to the log file using the configured logging methods.
- writeLogSeparator() : void
- Writes a separator line to the log file.
Properties
$logHelper
public
bool
$logHelper
= false
$color
private
bool
$color
= true
$instance
private
static Logger|null
$instance
= null
$logImportant
private
array<string|int, mixed>
$logImportant
= []
$logMethods
private
array<string|int, mixed>
$logMethods
= []
$logPath
private
string
$logPath
= ''
Methods
configure()
Configures the logger with the provided settings.
public
configure([array<string|int, mixed>|null $settings = null ]) : void
Parameters
- $settings : array<string|int, mixed>|null = null
-
Configuration settings for the logger.
getInstance()
Returns the singleton instance of the Logger class.
public
static getInstance([array<string|int, mixed>|null $settings = null ]) : Logger
If the instance does not exist, it creates one and configures it with the provided settings.
Parameters
- $settings : array<string|int, mixed>|null = null
-
Configuration settings for the logger.
Return values
Logger —The singleton instance of the Logger.
getLogHelper()
Returns the current state of the log helper.
public
getLogHelper() : bool
Return values
bool —Whether the log helper is enabled.
log()
Logs a message with specified level and backtrace information.
public
log([mixed $message = '' ][, string $level = 'info' ][, int|null $backtrace = null ][, int $spacing = 0 ][, bool $color = true ]) : void
Logs a message with the specified level and optional backtrace information.
Parameters
- $message : mixed = ''
-
The log message. Can be a string or an array.
- $level : string = 'info'
-
The log level (e.g., 'INFO', 'ERROR').
- $backtrace : int|null = null
-
Whether to include backtrace information. If true or a positive integer, backtrace is included.
- $spacing : int = 0
-
Controls spacing around the log message (0: no spacing, 1: before, 2: after, 3: both).
- $color : bool = true
-
Whether to use colored output.
logFormatter()
Formats the log message with optional color coding.
public
logFormatter(string $message, string $level[, string $trace = '' ][, bool $color = true ]) : string
Parameters
- $message : string
-
The log message.
- $level : string
-
The log level.
- $trace : string = ''
-
Optional backtrace information.
- $color : bool = true
-
Whether to use colored output.
Return values
string —The formatted log message.
setColor()
Enables or disables colored output in logs.
public
setColor(bool $color) : void
Parameters
- $color : bool
-
Whether to enable colored output.
setLogHelper()
Enables or disables the log helper.
public
setLogHelper([bool $logHelper = true ]) : void
Parameters
- $logHelper : bool = true
-
Whether to enable the log helper.
setLogImportantLevels()
Sets the log levels that are always outputted, even if the log helper is deactivated.
public
setLogImportantLevels([array<string|int, mixed> $importantLevels = [] ]) : void
Parameters
- $importantLevels : array<string|int, mixed> = []
-
Array of log levels that are always outputted (e.g., ['ERROR', 'SECURITY']).
setLogMethods()
Sets the methods used for logging.
public
setLogMethods([array<string|int, mixed> $logMethods = ['file_put', 'error_log'] ]) : void
Parameters
- $logMethods : array<string|int, mixed> = ['file_put', 'error_log']
-
Array of logging methods (e.g., ['file_put', 'error_log']).
setlogPathFolder()
Sets the path where log files will be stored.
public
setlogPathFolder(string $logPath) : void
Parameters
- $logPath : string
-
The path to the log directory.
writeLogMessage()
Writes a log message to the log file using the configured logging methods.
private
writeLogMessage(string $message, string $level[, string $trace = '' ]) : void
Parameters
- $message : string
-
The log message.
- $level : string
-
The log level.
- $trace : string = ''
-
Optional backtrace information.
writeLogSeparator()
Writes a separator line to the log file.
private
writeLogSeparator() : void