Logs messages to configured Log adapters. One or more adapters can be configured using Cake Log's methods. If you don't configure any adapters, and write to Log, the messages will be ignored.
You can configure log adapters in your applications config/app.php file.
A sample configuration would look like:
Log::setConfig('my_log', ['className' => 'FileLog']);
You can define the className as any fully namespaced classname or use a short hand
classname to use loggers in the App\Log\Engine & Cake\Log\Engine namespaces.
You can also use plugin short hand to use logging classes provided by plugins.
Log adapters are required to implement Psr\Log\LoggerInterface, and there is a
built-in base class (Cake\Log\Engine\BaseLog) that can be used for custom loggers.
Outside of the className key, all other configuration values will be passed to the
logging adapter's constructor as an array.
When configuring loggers, you can set which levels a logger will handle. This allows you to disable debug messages in production for example:
Log::setConfig('default', [
'className' => 'File',
'path' => LOGS,
'levels' => ['error', 'critical', 'alert', 'emergency']
]);
The above logger would only log error messages or higher. Any other log messages would be discarded.
When configuring loggers you can define the active scopes the logger is for. If defined, only the listed scopes will be handled by the logger. If you don't define any scopes an adapter will catch all scopes that match the handled levels.
Log::setConfig('payments', [
'className' => 'File',
'scopes' => ['payment', 'order']
]);
The above logger will only capture log entries made in the
payment and order scopes. All other scopes including the
undefined scope will be ignored.
You write to the logs using Log::write(). See its documentation for more information.
By default Cake Log supports all the log levels defined in
RFC 5424. When logging messages you can either use the named methods,
or the correct constants with write():
Log::error('Something horrible happened');
Log::write(LOG_ERR, 'Something horrible happened');
When logging messages and configuring log adapters, you can specify 'scopes' that the logger will handle. You can think of scopes as subsystems in your application that may require different logging setups. For example in an e-commerce application you may want to handle logged errors in the cart and ordering subsystems differently than the rest of the application. By using scopes you can control logging for each part of your application and also use standard log levels.
Registry of loaded log engines
A trait providing an object short-cut method to logging.