single class psr logger implementation

dev-master 2016-08-07 02:23 UTC

This package is auto-updated.

Last update: 2024-04-29 03:50:15 UTC


(single class psr compatible php logger)

Build Status

basic usage:

use def\Logger\Logger;

$logger = new Logger('php-app'); // or Logger::getLogger('php-app');

Now you can set a callable writer to process log messages:


// or
// will print_r every 10 records formatted with default formatter
$logger->setWriter('print_r', Logger::ALL, 10);

There are some writers already defined, for example:

$logger->setStreamWriter(STDERR, Logger::DEBUG | Logger::INFO); // there are also error_log, syslog and mail writers

You can change default formatting:

$logger->setDefaultFormatter(function ($levelname, $message, array $context) {

or pass custom formatter with writer:

$logger->setWriter('print_r', Logger::ALL, 10, function ($levelname, $message, array $context) {

It is possible to disable some levels for handling:

$logger->disable(Logger::DEBUG | Logger::INFO);

addContextProcessor method allows add some extra data to context:

$logger->addContextProcessor('some_key', function (array $context) {
    return 'some_value';