CakePHP logging library with support for multiple different streams

Maintainers

👁 cakephp

Package info

github.com/cakephp/log

Homepage

Issues

Forum

pkg:composer/cakephp/log

Statistics

Installs: 7 829 138

Dependents: 11

Suggesters: 3

Stars: 24

5.4.0-RC1 2026-03-13 17:44 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

Conflicts

None

Replaces

None

MIT eb0abf2ad54f1603bb6f2a8cc3bba6a330f0fc38

logloggingcakephpStreams

This package is auto-updated.

Last update: 2026-06-08 04:46:22 UTC


README

👁 Total Downloads
👁 License

CakePHP Logging Library

The Log library provides a Log service locator for interfacing with multiple logging backends using a simple interface. With the Log class it is possible to send a single message to multiple logging backends at the same time or just a subset of them based on the log level or context.

By default, you can use File or Syslog as logging backends, but you can use any object implementing Psr\Log\LoggerInterface as an engine for the Log class.

Usage

You can define as many or as few loggers as your application needs. Loggers should be configured using Cake\Log\Log. An example would be:

use Cake\Log\Log;

// Short classname
Log::setConfig('local', [
 'className' => 'File',
 'levels' => ['notice', 'info', 'debug'],
 'file' => '/path/to/file.log',
]);

// Fully namespaced name.
Log::setConfig('production', [
 'className' => \Cake\Log\Engine\SyslogLog::class,
 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
]);

It is also possible to create loggers by providing a closure.

Log::setConfig('special', function () {
	// Return any PSR-3 compatible logger
	return new MyPSR3CompatibleLogger();
});

Or by injecting an instance directly:

Log::setConfig('special', new MyPSR3CompatibleLogger());

You can then use the Log class to pass messages to the logging backends:

Log::write('debug', 'Something did not work');

Only the logging engines subscribed to the log level you are writing to will get the message passed. In the example above, only the 'local' engine will get the log message.

Filtering messages with scopes

The Log library supports another level of message filtering. By using scopes, you can limit the logging engines that receive a particular message.

// Configure /logs/payments.log to receive all levels, but only
// those with `payments` scope.
Log::setConfig('payments', [
 'className' => 'File',
 'levels' => ['error', 'info', 'warning'],
 'scopes' => ['payments'],
 'file' => '/logs/payments.log',
]);

Log::warning('this gets written only to payments.log', ['scope' => ['payments']]);

Documentation

Please make sure you check the official documentation