Skip to content
This repository was archived by the owner on Apr 7, 2020. It is now read-only.

Commit 8299349

Browse files
committed
First version release
0 parents  commit 8299349

5 files changed

+791
-0
lines changed

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Javier Eguiluz
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
EasyLogHandler (human-friendly log files)
2+
=========================================
3+
4+
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.
5+
6+
**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.
7+
8+
1. [Features](#features)
9+
2. [Installation](#installation)
10+
3. [Configuration and Usage](#configuration-and-usage)
11+
12+
----
13+
14+
Features
15+
--------
16+
17+
These are some of the best features of **EasyLogHandler** and how it compares itself with the default Symfony logs.
18+
19+
### Better Log Structure
20+
21+
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:
22+
23+
| Symfony | EasyLogHandler
24+
| ------- | --------------
25+
| ![structure-overview-symfony-mini](https://cloud.githubusercontent.com/assets/73419/17691467/e838b0b2-6394-11e6-9028-bfa04adc36c1.png) | ![structure-overview-easylog-mini](https://cloud.githubusercontent.com/assets/73419/17691466/e8336c88-6394-11e6-9a13-32146e2bdb6f.png)
26+
27+
EasyLogHandler structures the log files in a different way:
28+
29+
![structure-easylog](https://cloud.githubusercontent.com/assets/73419/17691552/788c4138-6395-11e6-8436-36051a4eb0da.png)
30+
31+
* It adds a large header and some new lines to separate each request logs;
32+
* If the request is less significant (e.g. Assetic requests) the header is more compact and displays less information;
33+
* Log messages are divided internally so you can better understand their different parts (request, doctrine, security, etc.)
34+
35+
### Less Verbose Logs
36+
37+
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.
38+
39+
| Symfony | EasyLogHandler
40+
| ------- | --------------
41+
| ![timestamps-symfony](https://cloud.githubusercontent.com/assets/73419/17691577/9f0bce78-6395-11e6-8e6b-f2ae3354342b.png) | ![timestamps-easylog](https://cloud.githubusercontent.com/assets/73419/17691578/9f4ceed0-6395-11e6-96ea-aada7577e1b2.png)
42+
43+
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:
44+
45+
| Symfony
46+
| -------
47+
| ![extra-symfony](https://cloud.githubusercontent.com/assets/73419/17691601/c17f2996-6395-11e6-876b-fbd87422c04d.png)
48+
49+
| EasyLogHandler
50+
| -------
51+
| ![extra-easylog](https://cloud.githubusercontent.com/assets/73419/17691600/c13fe75e-6395-11e6-92db-bb8457967642.png)
52+
53+
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.
54+
55+
However, for humans this "feature" is disturbing. That's why EasyLogHandler automatically replaces any placeholder included in the log message:
56+
57+
| Symfony
58+
| -------
59+
| ![placeholders-symfony](https://cloud.githubusercontent.com/assets/73419/17691694/541e4a20-6396-11e6-8400-546383a69755.png)
60+
61+
| EasyLogHandler
62+
| --------------
63+
| ![placeholder-easylog](https://cloud.githubusercontent.com/assets/73419/17691695/545b2f9e-6396-11e6-9b46-814c6dcde9e0.png)
64+
65+
### Better Visual Hierarchy
66+
67+
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?
68+
69+
| Symfony
70+
| -------
71+
| ![visual-hierarchy-symfony](https://cloud.githubusercontent.com/assets/73419/17691756/a0164edc-6396-11e6-949a-73e973219d13.png) <br> (all messages look exactly the same)
72+
73+
| EasyLogHandler
74+
| --------------
75+
| ![visual-hierarchy-easylog](https://cloud.githubusercontent.com/assets/73419/17691755/9fe3b86e-6396-11e6-9308-abaeb8c5b823.png) <br> (deprecations, warnings, errors and security messages stand out)
76+
77+
### Dynamic Variable Inlining
78+
79+
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.
80+
81+
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:
82+
83+
![dynamic-inline-easylog](https://cloud.githubusercontent.com/assets/73419/17691843/2fde6324-6397-11e6-8627-e7c04528c6b3.png)
84+
85+
### Stack Traces
86+
87+
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:
88+
89+
| Symfony
90+
| -------
91+
| ![stack-trace-symfony](https://cloud.githubusercontent.com/assets/73419/17691905/716839d2-6397-11e6-8d45-b8be84ad9596.png)
92+
93+
| EasyLogHandler
94+
| --------------
95+
| ![stack-trace-easylog](https://cloud.githubusercontent.com/assets/73419/17691908/72190302-6397-11e6-95c0-8c9c0b570d97.png)
96+
97+
### Log Message Grouping
98+
99+
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.
100+
101+
For example, this is a Symfony log file displaying three consecutive missing translation messages:
102+
103+
![translation-group-symfony](https://cloud.githubusercontent.com/assets/73419/17691954/b76ef04c-6397-11e6-9127-675ae831fd31.png)
104+
105+
And this is how the same messages are displayed by EasyLogHandler:
106+
107+
![translation-group-easylog](https://cloud.githubusercontent.com/assets/73419/17691955/b895ca86-6397-11e6-83c8-e5d6da4dbdf3.png)
108+
109+
The difference is even more evident for "event notified" messages, which usually generate tens of consecutive messages:
110+
111+
| Symfony
112+
| -------
113+
| ![event-group-symfony](https://cloud.githubusercontent.com/assets/73419/17691951/b447634a-6397-11e6-8482-265d7b02ead6.png)
114+
115+
| EasyLogHandler
116+
| --------------
117+
| ![event-group-easylog](https://cloud.githubusercontent.com/assets/73419/17691952/b5f5fd96-6397-11e6-8fc6-8835e6be7824.png)
118+
119+
Installation
120+
------------
121+
122+
This project is distributed as a PHP package instead of a Symfony bundle, so you just need to require the project with [Composer](https://getcomposer.org):
123+
124+
```bash
125+
$ composer require easycorp/easy-log-handler
126+
```
127+
128+
Configuration and Usage
129+
-----------------------
130+
131+
### Step 1
132+
133+
Define a new service in your application for this log handler:
134+
135+
```yaml
136+
# app/config/services.yml
137+
services:
138+
# ...
139+
easycorp.easylog.handler:
140+
class: EasyCorp\EasyLog\EasyLogHandler
141+
arguments:
142+
- '%kernel.logs_dir%/%kernel.environment%.log'
143+
```
144+
145+
### Step 2
146+
147+
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:
148+
149+
```yaml
150+
# app/config/config_dev.yml
151+
monolog:
152+
handlers:
153+
buffered:
154+
type: buffer
155+
handler: easylog
156+
channels: ["!event"]
157+
level: debug
158+
easylog:
159+
type: service
160+
id: easycorp.easylog.handler
161+
```
162+
163+
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.
164+
165+
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.
166+
167+
Use the `buffered` handler to configure the channels logged/excluded and the level of the messages being logged.

composer.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "easycorp/easy-log-handler",
3+
"description": "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.",
4+
"keywords": ["log", "logging", "monolog", "easy", "productivity"],
5+
"homepage": "https://github.com/EasyCorp/easy-log-handler",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Javier Eguiluz",
10+
"email": "[email protected]"
11+
},
12+
{
13+
"name": "Project Contributors",
14+
"homepage": "https://github.com/EasyCorp/easy-log-handler"
15+
}
16+
],
17+
"require": {
18+
"php" : ">=5.3.0",
19+
"monolog/monolog" : "~1.6",
20+
"symfony/yaml" : "~2.3|~3.0",
21+
},
22+
"autoload": {
23+
"psr-4": { "EasyCorp\\EasyLog\\": "src" },
24+
}
25+
}

0 commit comments

Comments
 (0)