New in Symfony: Streamlined Log Files
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:
Which Information is Missing?¶
Newer Symfony versions no longer log the information of the
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]
! 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.
Improving Your Logs¶
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:
- How to log messages to different files, which is useful to store the messages from some channels in log files different than dev.log and prod.log.
- How to easily create new log channels, so you can process those messages differently or store them in separate files.
- How to inject a preconfigured logger into services so the generated messages are logged in the given channel.
New in Symfony: Streamlined Log Files symfony.com/blog/new-in-symfony-streamlined-log-filesTweet this
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.