easycorp/easy-log-handler
最新稳定版本:v1.0.9
Composer 安装命令:
composer require easycorp/easy-log-handler
包简介
A handler for Monolog that optimizes log messages to be processed by humans instead of software. Improve your productivity with logs that are easy to understand.
README 文档
README
Symfony log files are formatted in the same way for all environments. This means that dev.log is optimized for machines instead of humans. The result is a log file bloated with useless information that makes you less productive.
EasyLogHandler is a new Monolog handler that creates human-friendly log files. It's optimized to display the log information in a clear and concise way. Use it in the development environment to become a much more productive developer.
Features
These are some of the best features of EasyLogHandler and how it compares itself with the default Symfony logs.
Better Log Structure
Symfony log files are a huge stream of text. When you open them, you can't easily tell when a request started or finished and which log messages belong together:
| Symfony | EasyLogHandler |
|---|---|
![]() |
![]() |
EasyLogHandler structures the log files in a different way:
- It adds a large header and some new lines to separate each request logs;
- If the request is less significant (e.g. Assetic requests) the header is more compact and displays less information;
- Log messages are divided internally so you can better understand their different parts (request, doctrine, security, etc.)
Less Verbose Logs
First of all, EasyLogHandler doesn't display the timestamp in every log message. In the dev environment you shouldn't care about that, so the timestamp is only displayed once for each group of log messages.
| Symfony | EasyLogHandler |
|---|---|
![]() |
![]() |
The extra information, which some log messages include to add more details about the log, is displayed only when it's different from the previous log. In contrast, Symfony always displays the extra for all logs, generating a lot of duplicated information:
| Symfony |
|---|
![]() |
| EasyLogHandler |
|---|
![]() |
It's becoming increasingly popular to use placeholders in log messages instead of the actual values (e.g. Matched route "{route}". instead of Matched route "home".) This is great for machines, because they can group similar messages that only vary in the placeholder values.
However, for humans this "feature" is disturbing. That's why EasyLogHandler automatically replaces any placeholder included in the log message:
| Symfony |
|---|
![]() |
| EasyLogHandler |
|---|
![]() |
Better Visual Hierarchy
Important elements, such as deprecations and security-related messages, must stand out in log files to help you spot them instantly. However, in Symfony all logs look exactly the same. How can you know which are the important ones?
| Symfony |
|---|
(all messages look exactly the same) |
| EasyLogHandler |
|---|
(deprecations, warnings, errors and security messages stand out) |
Dynamic Variable Inlining
Log messages usually contain related variables in their context and extra properties. Displaying the content of these variables in the log files is always a tough balance between readability and conciseness.
EasyLogHandler decides how to inline these variables dynamically depending on each log message. For example, Doctrine query parameters are always inlined but request parameters are inlined for unimportant requests and nested for important requests:
Stack Traces
When log messages include error stack traces, you definitely want to take a look at them. However, Symfony displays stack traces inlined, making them impossible to inspect. EasyLogHandler displays them as proper stack traces:
| Symfony |
|---|
![]() |
| EasyLogHandler |
|---|
![]() |
Log Message Grouping
One of the most frustrating experiences when inspecting log files is having lots of repeated or similar consecutive messages. They provide little information and they just distract you. EasyLogHandler process all log messages at once instead of one by one, so it's aware when there are similar consecutive logs.
For example, this is a Symfony log file displaying three consecutive missing translation messages:
And this is how the same messages are displayed by EasyLogHandler:
The difference is even more evident for "event notified" messages, which usually generate tens of consecutive messages:
| Symfony |
|---|
![]() |
| EasyLogHandler |
|---|
![]() |
Installation
This project is distributed as a PHP package instead of a Symfony bundle, so you just need to require the project with Composer:
$ composer require --dev easycorp/easy-log-handler
Configuration and Usage
Step 1
Define a new service in your application for this log handler:
Newer Symfony version:
# config/packages/dev/easy_log_handler.yaml services: EasyCorp\EasyLog\EasyLogHandler: public: false arguments: ['%kernel.logs_dir%/%kernel.environment%.log']
Older Symfony version:
# app/config/services.yml services: # ... easycorp.easylog.handler: class: EasyCorp\EasyLog\EasyLogHandler public: false arguments: - '%kernel.logs_dir%/%kernel.environment%.log'
Step 2
Update your Monolog configuration in the dev environment to define a buffered handler
that wraps this new handler service (keep reading to understand why).
You can safely copy+paste this configuration:
Newer Symfony version:
# config/packages/dev/monolog.yaml monolog: handlers: buffered: type: buffer handler: easylog channels: ['!event'] level: debug easylog: type: service id: EasyCorp\EasyLog\EasyLogHandler
Older Symfony version:
# app/config/config_dev.yml monolog: handlers: buffered: type: buffer handler: easylog channels: ["!event"] level: debug easylog: type: service id: easycorp.easylog.handler
Most log handlers treat each log message separately. In contrast, EasyLogHandler advanced log processing requires each log message to be aware of the other logs (for example to merge similar consecutive messages). This means that all the logs associated with the request must be captured and processed in batch.
In the above configuration, the buffered handler saves all log messages and then passes them to the EasyLog handler, which processes all messages at once and writes the result in the log file.
Use the buffered handler to configure the channels logged/excluded and the level of the messages being logged.
easycorp/easy-log-handler 适用场景与选型建议
easycorp/easy-log-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.86M 次下载、GitHub Stars 达 2.08k, 最近一次更新时间为 2016 年 08 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「logging」 「monolog」 「easy」 「productivity」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 easycorp/easy-log-handler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 easycorp/easy-log-handler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 easycorp/easy-log-handler 相关的其它包
同方向 / 同关键字的高下载量 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
统计信息
- 总下载量: 10.86M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2083
- 点击次数: 29
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-08-16

















