If you have created a new Symfony project recently, you may have noticed a big
change in the development log file. In the past, even the simplest page load
generated tens of lines in the dev.log
file. In the latest Symfony versions,
by default only the important information is logged.
This image clearly shows the differences in the dev.log
file created by the
simple Welcome to Symfony page. In Symfony 2.7.7 it contained 63 lines, but in
the Symfony 2.7.9 version it only contains 3 lines:
Newer Symfony versions no longer log the information of the event
channel,
which produced messages like these:
1 2 3 | event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". [] []
event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". [] []
...
|
We did this by changing the default configuration of the Symfony Standard edition:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # app/config/config_dev.yml
# BEFORE
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
# AFTER
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: [!event]
|
The !
prefix tells Monolog to log all channels except event
. You can
exclude more channels (e.g. channels: [!event, !doctrine]
) and you can leave
it empty to start logging event messages again.
In addition, this change can be applied to all your existing Symfony applications,
regardless of the Symfony version they use. Just add channels: [!event]
to
your Monolog configuration in config_dev.yml
and say goodbye to those
annoying log messages.
Monolog, the library used by Symfony to log contents through the MonologBundle, is still heavily underused by most Symfony developers. As this article shows, even a minor configuration change can have a positive impact in your development experience. Don't forget to check out the documentation to learn:
What a Symfony developer should know about the framework: News, Jobs, Tweets, Events, Videos,...