2017 © Pedro Peláez
 

library 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.

image

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.

  • Friday, July 27, 2018
  • by javier.eguiluz
  • Repository
  • 13 Watchers
  • 743 Stars
  • 547,799 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 22 Forks
  • 3 Open issues
  • 9 Versions
  • 58 % Grown

The README.md

EasyLogHandler (human-friendly log files)

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., (*1)

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., (*2)

  1. Features
  2. Installation
  3. Configuration and Usage

Features

These are some of the best features of EasyLogHandler and how it compares itself with the default Symfony logs., (*3)

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:, (*4)

Symfony EasyLogHandler
structure-overview-symfony-mini structure-overview-easylog-mini

EasyLogHandler structures the log files in a different way:, (*5)

structure-easylog, (*6)

  • 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., (*7)

Symfony EasyLogHandler
timestamps-symfony timestamps-easylog

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:, (*8)

| Symfony , (*9)

extra-symfony

| EasyLogHandler , (*10)

extra-easylog

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., (*11)

However, for humans this "feature" is disturbing. That's why EasyLogHandler automatically replaces any placeholder included in the log message:, (*12)

| Symfony , (*13)

placeholders-symfony

| EasyLogHandler , (*14)

placeholder-easylog

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?, (*15)

| Symfony , (*16)

visual-hierarchy-symfony
(all messages look exactly the same)

| EasyLogHandler , (*17)

visual-hierarchy-easylog
(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., (*18)

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:, (*19)

dynamic-inline-easylog, (*20)

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:, (*21)

| Symfony , (*22)

stack-trace-symfony

| EasyLogHandler , (*23)

stack-trace-easylog

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., (*24)

For example, this is a Symfony log file displaying three consecutive missing translation messages:, (*25)

translation-group-symfony, (*26)

And this is how the same messages are displayed by EasyLogHandler:, (*27)

translation-group-easylog, (*28)

The difference is even more evident for "event notified" messages, which usually generate tens of consecutive messages:, (*29)

| Symfony , (*30)

event-group-symfony

| EasyLogHandler , (*31)

event-group-easylog

Installation

This project is distributed as a PHP package instead of a Symfony bundle, so you just need to require the project with Composer:, (*32)

$ composer require --dev easycorp/easy-log-handler

Configuration and Usage

Step 1

Define a new service in your application for this log handler:, (*33)

Newer Symfony version:, (*34)

# config/packages/dev/easy_log_handler.yaml
services:
    EasyCorp\EasyLog\EasyLogHandler:
        public: false
        arguments: ['%kernel.logs_dir%/%kernel.environment%.log']

Older Symfony version:, (*35)

# 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:, (*36)

Newer Symfony version:, (*37)

# 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:, (*38)

# 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., (*39)

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., (*40)

Use the buffered handler to configure the channels logged/excluded and the level of the messages being logged., (*41)

The Versions

27/07 2018

dev-master

9999999-dev https://github.com/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.

  Sources   Download

MIT

The Requires

 

log logging monolog easy productivity

27/07 2018

v1.0.7

1.0.7.0 https://github.com/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.

  Sources   Download

MIT

The Requires

 

log logging monolog easy productivity

27/07 2018

v1.0.6

1.0.6.0 https://github.com/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.

  Sources   Download

MIT

The Requires

 

log logging monolog easy productivity

12/06 2018

v1.0.5

1.0.5.0 https://github.com/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.

  Sources   Download

MIT

The Requires

 

log logging monolog easy productivity

10/01 2018

v1.0.4

1.0.4.0 https://github.com/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.

  Sources   Download

MIT

The Requires

 

log logging monolog easy productivity

20/10 2017

v1.0.3

1.0.3.0 https://github.com/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.

  Sources   Download

MIT

The Requires

 

log logging monolog easy productivity

31/08 2016

v1.0.2

1.0.2.0 https://github.com/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.

  Sources   Download

MIT

The Requires

 

log logging monolog easy productivity

17/08 2016

v1.0.1

1.0.1.0 https://github.com/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.

  Sources   Download

MIT

The Requires

 

log logging monolog easy productivity

16/08 2016

v1.0.0

1.0.0.0 https://github.com/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.

  Sources   Download

MIT

The Requires

 

log logging monolog easy productivity