Logger
in package
FinalYes
Logging utility class.
Provides static methods for logging messages at different levels (debug, info, error)
with automatic file/line/class information. Logs are written to the path defined
in application/config/config.php#log_path.
Table of Contents
Methods
- debug() : void
- Debug log.
- display() : void
- Log to browser or console.
- error() : void
- Error log.
- info() : void
- Info log.
- createMessage() : string
- Create a log message.
Methods
debug()
Debug log.
public
static debug(mixed ...$params) : void
use \X\Util\Logger;
Logger::debug('User logged in', ['user_id' => 123]);
Logger::debug($user, $request->all());
Parameters
- $params : mixed
-
Log Message.
display()
Log to browser or console.
public
static display(mixed ...$params) : void
use \X\Util\Logger;
// In browser: displays formatted HTML
// In CLI: outputs to console and writes to log file
Logger::display('Debug value:', $someVariable);
Logger::display($user, $request->all());
Parameters
- $params : mixed
-
Log Message.
error()
Error log.
public
static error(mixed ...$params) : void
use \X\Util\Logger;
Logger::error('Database connection failed');
Logger::error($exception); // Exception objects are automatically formatted
Logger::error('API error', ['status' => 500, 'response' => $body]);
Parameters
- $params : mixed
-
Log Message.
info()
Info log.
public
static info(mixed ...$params) : void
use \X\Util\Logger;
Logger::info('Processing started');
Logger::info('Order created', ['order_id' => 456, 'total' => 1000]);
Parameters
- $params : mixed
-
Log Message.
createMessage()
Create a log message.
private
static createMessage(array<string|int, mixed> $params, array<string|int, mixed>|null $trace[, bool $isBrowser = false ]) : string
Parameters
- $params : array<string|int, mixed>
-
Log Message.
- $trace : array<string|int, mixed>|null
-
(optional) Stack traces.
- $isBrowser : bool = false
-
(optional) If true, escapes HTML special characters in log messages. Default is false.
Return values
string —Log Message.