netpromotion / lazy-logger
Psr\Log\LoggerInterface implementation which creates real logger only if it is needed
Installs: 1 869
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=5.6
- psr/log: ^1.1
Requires (Dev)
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-11-11 21:12:02 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); }