alexandre-daubois/monolog-processor-collection
Composer 安装命令:
composer require alexandre-daubois/monolog-processor-collection
包简介
A collection of Monolog processors
关键字:
README 文档
README
Welcome to the Monolog Processor Collection (MPC) - the ultimate suite of processors designed to enhance your logging with the renowned Monolog library. This toolkit is meticulously crafted to integrate seamlessly with PHP 8.1+, ensuring your logging captures the comprehensive details you need with minimal overhead.
MPC is engineered for developers who demand more from their logs. Whether you're tracking down elusive bugs or monitoring live production environments, processors enrich your log entries with invaluable context, turning ordinary logs into a rich, actionable dataset.
MPC is compatible with worker mode of web servers, as relevant processors implement the ResettableInterface.
Available Processors
The package provides the following processors:
BacktraceProcessoradds the backtrace to the log recordClientIpProcessoradds the client IP address to the log recordEnvVarProcessoradds the value of one or more environment variables to the log recordHighResolutionTimestampProcessoradds the high resolution time to the log recordIsHttpsProcessoradds a boolean value indicating whether the request is a secured HTTP request to the log recordPhpIniValueProcessoradds the value of one or more PHP ini settings to the log recordProtocolVersionProcessoradds the HTTP protocol version to the log recordRequestSizeProcessoradds the size of the request to the log record, headers included, in bytesResourceUsagesProcessoradds the resource usage to the log record as returned by getrusage()SapiNameProcessoradds the name of the SAPI to the log recordSessionIdProcessoradds the session ID to the log record, or null if no session is activeUuidProcessoradds a UUID v7 to the log record to track records triggered during the same request
Installation
The recommended way to install MPC is through Composer:
composer require alexandre-daubois/monolog-processor-collection
Usage
All processor can be used in the same way as any other Monolog processor. For example:
use Monolog\Logger; $logger = new Logger('name'); $logger->pushProcessor(new BacktraceProcessor());
Some processors, like EnvVarProcessor and PhpIniValueProcessor, require you to specify more
arguments. For example:
use Monolog\Logger; $logger = new Logger('name'); $logger->pushProcessor(new EnvVarProcessor(['APP_ENV', 'APP_DEBUG']));
Integration with Symfony and MonologBundle
You can register those processors to be used with Symfony and MonologBundle by adding the following configuration to
your config/packages/monolog.php file:
use Monolog\Processor\ProcessorInterface; use MonologProcessorCollection\BacktraceProcessor; use MonologProcessorCollection\EnvVarProcessor; use MonologProcessorCollection\ProtocolVersionProcessor; use MonologProcessorCollection\EnvVarProcessor; use MonologProcessorCollection\SapiNameProcessor; return static function (ContainerConfigurator $configurator): void { // ... // register as many processors as you like, but keep in mind that // each processor is called for each log record $services = $configurator->services(); $services ->set(BacktraceProcessor::class) ->set(EnvVarProcessor::class)->args(['APP_ENV']) ->set(ProtocolVersionProcessor::class) ->set(SapiNameProcessor::class); // ... };
If you don't use autoconfigure, you need to tag the processors with monolog.processor:
return static function (ContainerConfigurator $configurator): void { // ... $services = $configurator->services(); $services ->set(BacktraceProcessorAlias::class) ->tag('monolog.processor', ['handler' => 'main']) ->set(EnvVarProcessor::class)->args(['APP_ENV']) ->tag('monolog.processor', ['handler' => 'main']); // ... };
You can achieve the same configuration with YAML:
# config/packages/monolog.yaml services: MonologProcessorCollection\BacktraceProcessor: tags: - { name: monolog.processor, handler: main } MonologProcessorCollection\EnvVarProcessor: arguments: - APP_ENV tags: - { name: monolog.processor, handler: main }
Or XML:
<!-- config/packages/monolog.xml --> <!-- ... --> <service id="MonologProcessorCollection\BacktraceProcessor" public="false"> <tag name="monolog.processor" handler="main" /> </service> <service id="MonologProcessorCollection\EnvVarProcessor" public="false"> <argument>APP_ENV</argument> <tag name="monolog.processor" handler="main" /> </service>
alexandre-daubois/monolog-processor-collection 适用场景与选型建议
alexandre-daubois/monolog-processor-collection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.5k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2023 年 11 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「logging」 「monolog」 「collection」 「psr-3」 「PSR3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 alexandre-daubois/monolog-processor-collection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alexandre-daubois/monolog-processor-collection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 alexandre-daubois/monolog-processor-collection 相关的其它包
同方向 / 同关键字的高下载量 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
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.
PSR-3 compatible logger with dynamic file naming and hourly rotation, powered by Monolog
Asynchronous Sentry for Symfony - Fire and forget
统计信息
- 总下载量: 17.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-06