detain/tracy-monolog-adapter
Composer 安装命令:
composer require detain/tracy-monolog-adapter
包简介
Bridges the Tracy debugger with the Monolog logger so Tracy log output is routed through Monolog handlers and processors.
README 文档
README
A small bridge that lets the Tracy debugger log through a Monolog logger so you can route Tracy's log calls (warnings, errors, exceptions) through any Monolog handler, processor or formatter you already use.
Includes:
Detain\TracyHasMono\TracyMonoLogger— aTracy\ILoggerimplementation backed by aMonolog\Logger.Detain\TracyHasMono\Processors\TracyExceptionProcessor— a Monolog processor that renders anyThrowablefound in a record's context as a Tracy BlueScreen HTML file.Detain\TracyHasMono\Bridges\NetteDI\MonologExtension— an optional Nette DI compiler extension that wires everything into a container.Nextras\TracyMonologAdapter\Logger— a legacy alias kept for backwards compatibility with code that still imports the old namespace.
Requirements
| Dependency | Version |
|---|---|
| PHP | >=8.1 |
tracy/tracy |
^2.10 |
monolog/monolog |
^3.0 |
nette/di |
^3.0 (only for the Nette DI bridge) |
Installation
composer require detain/tracy-monolog-adapter
Usage
Plain PHP
Wire a Monolog logger and pass it to TracyMonoLogger, then register the
result with Tracy's Debugger.
use Detain\TracyHasMono\Processors\TracyExceptionProcessor; use Detain\TracyHasMono\TracyMonoLogger; use Monolog\Handler\RotatingFileHandler; use Monolog\Logger; use Tracy\BlueScreen; use Tracy\Debugger; require __DIR__ . '/vendor/autoload.php'; $logDir = __DIR__ . '/log'; Debugger::enable(Debugger::PRODUCTION, $logDir); $monolog = new Logger('app'); $monolog->pushHandler(new RotatingFileHandler($logDir . '/app.log')); $monolog->pushProcessor(new TracyExceptionProcessor($logDir, new BlueScreen())); Debugger::setLogger(new TracyMonoLogger($monolog));
After this, every call Tracy makes to its ILogger (warnings, errors,
uncaught exceptions, manual Debugger::log() calls) is routed through
your Monolog stack.
Priority mapping
TracyMonoLogger maps Tracy priority strings to Monolog Level cases:
| Tracy constant | Monolog Level |
|---|---|
ILogger::DEBUG |
Level::Debug |
ILogger::INFO |
Level::Info |
ILogger::WARNING |
Level::Warning |
ILogger::ERROR |
Level::Error |
ILogger::EXCEPTION |
Level::Critical |
ILogger::CRITICAL |
Level::Critical |
Unknown priorities fall back to Level::Error.
Throwable handling
When Debugger::log() is called with a Throwable, the throwable is
moved into the Monolog record context under the exception key. If you
have pushed TracyExceptionProcessor onto your logger, that processor
will:
- Render the throwable to a Tracy BlueScreen HTML file in the configured
log directory (file name
exception--Y-m-d--H-i--{hash}.html), reusing an existing file if one for the same hash is already present. - Add
tracy_filename(just the basename) andtracy_created(trueif this call wrote the file,falseif it pre-existed) to the record context. - Replace the record message with a human-readable summary of the throwable chain when the original message is empty.
Nette DI
Register the bundled compiler extension in your NEON config:
extensions: monolog: Detain\TracyHasMono\Bridges\NetteDI\MonologExtension
By default this registers:
monolog.handler—Monolog\Handler\RotatingFileHandlerpointing at%logDir%/nette.logmonolog.tracyExceptionProcessor—TracyExceptionProcessorpointing at%logDir%monolog.monologLogger—Monolog\Loggerchannelnettewith the handler and processor pre-pushedmonolog.tracyLogger—TracyMonoLoggerwrapping the above and replacing the autowiredtracy.loggerservice
After compilation the extension also injects
\Tracy\Debugger::setLogger($this->getByType(\Tracy\ILogger::class))
into the container's initialize() method, so Tracy itself begins
routing through Monolog as soon as the container boots.
To reuse an existing Monolog logger service instead of letting the extension create one, pass it via the extension config:
monolog: monolog: @myMonologLogger
Architecture
src/
├── Bridges/NetteDI/MonologExtension.php # Nette DI compiler extension
├── Logger.php # Legacy Nextras\TracyMonologAdapter alias
├── Processors/TracyExceptionProcessor.php # Monolog processor → BlueScreen HTML
└── TracyMonoLogger.php # Tracy ILogger → Monolog adapter
Two namespaces are exposed:
Detain\TracyHasMono\— the active namespace; use this in new code.Nextras\TracyMonologAdapter\— coversLogger.phponly, kept as a drop-in replacement for the original Nextras package.
License
New BSD License. See the license file for details.
Credits
Originally based on the Nextras Tracy-Monolog Adapter by the Nextras contributors, with portions (BlueScreen rendering, exception file naming, exception summary formatting) adapted from Nette Tracy by David Grudl. Maintained for the Detain project by the Detain Project contributors.
detain/tracy-monolog-adapter 适用场景与选型建议
detain/tracy-monolog-adapter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.73k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2018 年 08 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「monolog」 「logger」 「nette」 「detain」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 detain/tracy-monolog-adapter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 detain/tracy-monolog-adapter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 detain/tracy-monolog-adapter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A GeoIP decorator/processor for monolog
A Zend Framework module that sets up Monolog for logging in applications.
Laravel 5.6 Monolog custom telegram channel
Workflow logger
HTTP request logger middleware for Laravel
A Monolog processor to add X-Request-Id or UNIQUE_ID env to monolog stack if present, provide a default one otherwise. Optionally, add a forwarded request-id list.
统计信息
- 总下载量: 1.73k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2018-08-15