netpromotion / lazy-logger
Psr\Log\LoggerInterface 实现,仅在需要时创建真正的日志记录器
v1.0.0
2019-04-11 08:55 UTC
Requires
- php: >=5.6
- psr/log: ^1.1
Requires (Dev)
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-09-11 20:47:18 UTC
README
Psr\Log\LoggerInterface
实现,仅在需要时创建真正的日志记录器。
非常适合需要快速响应的入口点,但应使用像 Monolog 这样的健壮日志记录器进行错误记录。
<?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); }