miljan9602 / bugsnag-psr-logger
官方 Bugsnag PHP PSR Logger。
Requires
- php: >=5.5
- miljan9602/bugsnag: ^3.20
- psr/log: ^1.0
Requires (Dev)
- graham-campbell/testbench-core: ^1.1
- mockery/mockery: ^0.9.4
- phpunit/phpunit: ^4.8|^5.0
This package is auto-updated.
Last update: 2024-09-21 20:59:13 UTC
README
Bugsnag PHP PSR logger 是一个实现了 Fig PSR 日志标准 的实现,它提供了一个标准接口用于向 Bugsnag 日志。
入门
安装
将 bugsnag/bugsnag-psr-logger
添加到您的 composer.json
文件中。
配置
这个库提供了一个日志接口,但使用 bugsnag-php 通知库 作为基础。所有配置应按照 官方 bugsnag-php 文档 中描述的方式进行。
使用日志记录器
该库提供了两个日志记录器,BugsnagLogger
和 MultiLogger
。
BugsnagLogger
如果接收到严重性高于 info
的消息,会自动向 Bugsnag 发送通知。这允许您通过直接将日志记录器与您使用的框架接口来通知任何已处理的异常。确保通过在创建时传递 client
对象,使日志记录器可以与 bugsnag-php
库进行通信。
$bugsnag = Bugsnag\Client::make('YOUR-API-KEY-HERE'); $logger = new Bugsnag\PsrLogger\BugsnagLogger($bugsnag); # Will send a notification to bugsnag $logger->error('An error occurred');
如果您想在 BugsnagLogger
旁边使用另一个日志记录器,您需要使用 MultiLogger
。通过在构造时传递一个包含 Logger
对象的数组,MultiLogger
将按顺序调用每个传递的 Logger
来记录消息。
$logger = new Bugsnag\PsrLogger\BugsnagLogger($bugsnag); $mySecondLogger = new Logger(); $multiLogger = new Bugsnag\PsrLogger\MultiLogger([$logger, $mySecondLogger]); # Will log to $mySecondLogger and send a notification to bugsnag through $logger $multiLogger->error('An error occurred');
将日志发送到 Bugsnag 的默认级别是 Psr\Log\LogLevel::NOTICE
。这可以通过使用 setNotifyLevel
函数来覆盖。
$logger = new Bugsnag\PsrLogger\BugsnagLogger($bugsnag); # Will not send a notification to bugsnag by default $logger->info('Some interesting information'); $logger->setNotifyLevel(Psr\Log\LogLevel::INFO); # Will send a notification to bugsnag $logger->info('Some more interesting information');
有关将日志记录器集成到特定框架的更多信息,请参阅 bugsnag-php 文档 中的个别设置信息。
贡献
所有贡献者都欢迎!有关如何构建、测试和发布 bugsnag-psr-logger
的信息,请参阅我们的 贡献指南。请随意在 现有问题 上评论,以获得澄清或起点。
许可
Bugsnag PSR logger 是免费软件,在 MIT 许可下发布。有关详细信息,请参阅 LICENSE.txt。