Did you find something wrong?
Be sure to let us know about it with an
issue.
Thank you!
Log

Aplus Framework Log Library.
Getting Started
The Log Library allows you to save logs in several ways.
In the constructor of the Logger class it is possible to set the destination, the level and configurations through the config parameter.
Let's see an example saving logs with CRITICAL level (5) or higher in the app.log file:
use Framework\Log\Loggers\FileLogger;
use Framework\Log\LogLevel;
$destination = __DIR__ . '/app.log';
$level = LogLevel::CRITICAL;
$logger = new FileLogger($destination, $level);
$logger->logDebug('Debug message'); // bool
$logger->logCritical('Critical message'); // bool
$logger->logAlert('Alert message'); // bool
Note that logs with a level lower than CRITICAL (5) are not saved in the destination.
Log Levels
Logs can be defined at eight different levels:
WARNING
Level 3: Exceptional occurrences that are not errors.
Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
ERROR
Level 4: Runtime errors that do not require immediate action but should typically be logged and monitored.
CRITICAL
Level 5: Critical conditions.
Example: Application component unavailable, unexpected exception.
Loggers
The Log Library has five different loggers:
Email Logger
The message is sent by email to the address in the destination parameter.
use Framework\Log\Loggers\EmailLogger;
$destination = 'sysadmin@domain.tld';
$logger = new EmailLogger($destination);
In the third parameter of the constructor, config, you can set custom headers for the message:
$logger = new EmailLogger($destination, config: [
'headers' => [
'From' => 'system@domain.tld',
'Subject' => 'System Log',
],
]);
File Logger
The message is appended to the file destination.
use Framework\Log\Loggers\FileLogger;
$destination = __DIR__ . '/app.log';
$logger = new FileLogger($destination);
Multi File Logger
The message is appended to a file with the date in the filename with a directory as destination.
use Framework\Log\Loggers\MultiFileLogger;
$destination = __DIR__ . '/logs';
$logger = new MultiFileLogger($destination);
The filename has the following format: Y-m-d.log
Conclusion
Aplus Log Library is an easy-to-use tool for, beginners and experienced, PHP developers.
It is perfect for saving logs with different destinations.
The more you use it, the more you will learn.