netpromotion/lazy-logger

Psr\Log\LoggerInterface implementation which creates real logger only if it is needed

v1.0.0 2019-04-11 08:55 UTC

This package is auto-updated.

Last update: 2024-12-11 21:19:07 UTC


README

Psr\Log\LoggerInterface implementation which creates real logger only if it is needed.

Ideal for entry points which needs to be quick, but should use robust logger like Monolog for error logging.

<?php // entry-point.php

$logger = new Netpromotion\LazyLogger\LazyLogger(function () {
    return Symfony::getInstance()->getContainer()->get('logger');
});

try {
    doSomething();
    exit(0);
} catch (Exception $e) {
    $logger->error('Something went wrong.', [
        'message' => $e->getMessage(),
    ]);
    exit(-1);
}