How to turn off logging for symfony messenger component

Viewed 1687

I have a Symfony website that's something inbetween an actual implementation and staging (it's used by a special client of mine). The logging is kept ON on that server because that helps when things go wrong from time to time (and they often go wrong in non-obvious, non-error/exception ways). Most of the logged lines are by Doctrine - executed queries, which is very useful to me, but I do manually disable logging for SOME of the huge, repetitive and well-tested operations that spam hundreds of queries, to keep the log easier to navigate, if needed.

My question is: How do I disable logging done from inside of the Symfony messenger component? Specifically, logging done by the doctrine transport (which I use), which spams my log with following lines every second (multiplied by the number of supervisord processes that I run):

[2020-08-24 14:19:25] doctrine.DEBUG: "START TRANSACTION" [] []
[2020-08-24 14:19:25] doctrine.DEBUG: SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC LIMIT 1 FOR UPDATE ["2020-08-24 13:19:25","2020-08-24 14:19:25","default"] []
[2020-08-24 14:19:25] doctrine.DEBUG: "COMMIT" [] []

Since these messages are generated by doctrine, I can't filter them out through logging channels - because that would disable ALL doctrine log messages, and that's not what I want. I also don't want to raise the logging level to something higher than DEBUG. I want to remove ONLY these specific messages from the log.

2 Answers

You have many options.

Exclude messenger log info: Disable Symfony Messenger log info

Log your message in a different file:

You can log Messages to different Files. Like it's described in this part of the Symfony documentation.

Configure the logger level:

You can configure your logger entry with level info, that can help you to have a log file corresponding to what you want to see. For example, you can use the ERROR level to just have errors in your Message.

Check the documentation below Loggin component.

Create your own channel:

You can create your own channel and subscribe to it, that excludes doctrine. Creating your own channel

Just search what you want with grep:

If you want to filter more what you want to see when you read the log file, you can use grep like:

tail path/to/my/logfile.txt | grep 'what I want to see'

That permits us to avoid useless lines. grep man page

I just wanted to tackle this issue and I found that most of the spam can be avoided by using a fingers_crossed monolog handler instead of the default one. This quick solution avoid to fully disable Doctrine logs.

In packages/dev/monolog.yaml, replace

main:
    type: stream
    path: "%kernel.logs_dir%/%kernel.environment%.log"
    level: debug
    channels: ["!event"]

by :

main:
    type: fingers_crossed
    action_level: info
    handler: nested
    channels: ["!event"]
nested:
    type: stream
    path: "%kernel.logs_dir%/%kernel.environment%.log"
    level: debug
    channels: ["!event"]
Related