bgalati/monolog-sentry-handler
Composer 安装命令:
composer require bgalati/monolog-sentry-handler
包简介
Sentry handler for PHP SDK v2/v3
README 文档
README
It is a Monolog handler for Sentry PHP SDK v2, v3 and v4 with breadcrumbs support.
Features
- Send each log record to a Sentry server
- Send log records as breadcrumbs when they are handled in batch; the main reported log record is the one with the highest log level
- Send log along with exception when one is set in the main log record context
- Customize data sent to Sentry to fit your needs
- Compatible with Monolog 1, 2 and 3
Installation
The suggested installation method is via composer:
# For Sentry PHP SDK v3/v4 composer require bgalati/monolog-sentry-handler # For Sentry PHP SDK v2 composer require bgalati/monolog-sentry-handler:^1.2
Basic usage
<?php use BGalati\MonologSentryHandler\SentryHandler; use Sentry\State\Hub; $sentryHandler = new SentryHandler(Hub::getCurrent()); /** @var $logger Monolog\Logger */ $logger->pushHandler($sentryHandler); // Add records to the log $logger->debug('Foo'); $logger->error('Bar');
Check out the handler constructor to know how to control the minimum logging level and bubbling.
Note
- It is a good idea to combine this handler with a
FingersCrossedHandlerand aBufferHandlerto leverage Sentry breadcrumbs. It gives maximum context for each Sentry event.Look at the symfony guide for a complete example with Monolog and symfony
Documentation
- Symfony guide: it gives a way to integrate this handler to your app
- Working example with Symfony
- Extension points: Customize data sent to Sentry and more
FAQ
What are the differences with the official Monolog Sentry handlers?
At the moment the official SDK proposes two Monolog handlers:
Sentry\Monolog\Handler: each logs becomes a Sentry event- Depending on the setup it can create a lot of noise.
Sentry\Monolog\BreadcrumbHandler: each logs is added as a breadcrumb in the current event- It cannot be used only with Monolog: it requires default integrations to work correctly.
Both of them don't send event immediately. Thus, sending Sentry events happens; either when PHP process terminates or when the flush is done explicitly.
This lib proposes a Handler that is different:
- It flushes Sentry events on each call: looks like a standard for Monolog handlers
- It adds log records as breadcrumbs when it is used with a buffering handler like
FingersCrossedHandler
What about contributing it to the Monolog project?
As per this comment, Monolog project does not accept new handler with 3rd party dependencies.
For new handlers with third-party dependencies IMO the right way is to publish as a third-party package, with requires on monolog and on whichever dependency is needed. It lets Composer resolve everything which makes more sense really.
Contributing
Fork me.
Install dependencies with make vendor.
Run tests with make tests.
Changelog
See CHANGELOG.md.
Credits
bgalati/monolog-sentry-handler 适用场景与选型建议
bgalati/monolog-sentry-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 925.03k 次下载、GitHub Stars 达 59, 最近一次更新时间为 2019 年 08 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 bgalati/monolog-sentry-handler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bgalati/monolog-sentry-handler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 925.03k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 59
- 点击次数: 21
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-08-17
