Logging in li3 is handled through the
Logger class. This class is designed to provide a consistent interface for writing log messages across the application. The
Logger class can also be set up with a series of named configurations that contain a log adapter to write to.
When configuring adapters, you may specify one or more priorities for each, using the
'priority' key. This key can be a single priority level (string), or an array of multiple levels. When a log message is written, all adapters that are configured to accept the priority level with which the message was written will receive the message.
Logger::config([ 'default' => ['adapter' => 'Syslog'], 'badnews' => [ 'adapter' => 'File', 'priority' => ['emergency', 'alert', 'critical', 'error'] ] ]);
Logger class has a single public function called
write(). This is the method used to write log messages. li3 also allows you to use the priority as the method name. For instance, in the above configuration example, you could call the
// Using the `write()` method: Logger::write('critical', 'This is a critical message'); // is the same as: Logger::critical('This is a critical message');
By default, the logger will write a message to any adapter that has the specified priority in the log message in its configuration. To write to an adapter other than the default adapter(s), you can use the options parameter which expects an array.
Logger::write('critical', 'This is a critical message', ['name' => 'badnews']);