nomad42/loggable
最新稳定版本:0.2.1
Composer 安装命令:
composer require nomad42/loggable
包简介
PSR-3 compatible log message interface
关键字:
README 文档
README
This package have PSR-3 compatible log message interface.
It can be useful for implementation messages that can be easily logged via \Psr\Log\LoggerInterface::log method.
Installation
You can install the package via composer:
composer require nomad42/loggable
Usage
Standardize the workflow with logging your exception.
Step 1.
Implement interface in your exception.
class MyAppException extends Exception implements Loggable { public function getLevel(): string { return LogLevel::CRITICAL; } public function getContext(): array { return ['exception' => $this]; } }
Step 2.
At your error handler add one extra catch block.
$logger = new NullLogger(); try { throw new MyAppException('Oh no!'); } catch (Loggable $exception) { // <- this block; yes, it can be caught $logger->log( $exception->getLevel(), $exception->getMessage(), $exception->getContext(), ); } catch (Exception $exception) { $logger->error('Oh no!', ['exception' => $exception]); }
Wrap existing exception and log it immediately
$exception = new \Exception('Oh no!'); $logger = new \Psr\Log\NullLogger(); LogMessage::makeFromException($exception)->logByLogger($logger);
Log some data in easy way
(new LogMessage( PsrLogLevel::INFO, 'Cron task end successfully', ['metrics' => $metrics], ))->logByLogger($logger);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-24