How to turn off logging for symfony messenger component
Asked Answered
E

3

6

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.

Extension answered 24/8, 2020 at 14:25 Comment(3)
sure, you could filter them via channel doctrine: channels: ['!doctrine'] or send doctrine channel messages to a different log to not clutter your "standard" log.Outman
plus you could increase the log level to avoid seeing debug messages - or you could use "fingers crossed" to just log everything when a certain error level is reached. you'll have to be more specific in what you actually want to achieve?Outman
@Outman Sorry, I've updated my question a little bit to make it more clear (english isn't my first language - I thought I was already clear enough), but I want to disable ONLY the doctrine log messages that are logged from the symfony messaging component. Disabling the entire doctrine logging channel is definitely NOT what I want. Nor is to ignore ALL debug level messages.Extension
A
2

The straight solution was when running the consumer use the flag --no-debug

php bin/console messenger:consume async_email_handler --no-debug

This will stop writing the doctrine lines in the .log file

Antivenin answered 13/12, 2022 at 22:35 Comment(0)
A
1

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

Apprise answered 24/8, 2020 at 16:19 Comment(9)
Thanks for your answer, but none of these solutions work for me. Logging doctrine channel to a different file won't remove the spammy messages generated by the messenger component, and will just make the sequence of events harder to follow. Raising the error level is not what I want to do (as noted in the question), i DO want most DEBUG-level messages to stay. Excluding the entire doctrine channel is also not what I want to do. Finally, gerping the file doesn't answer my question and would be difficult to do in such way to only remove some of these messages.Extension
Otherwise, you should go deeper inside the Logger component, understand how what you don't want works and rewrite your own as you want. If I understand well, you want doctrine channel but not all doctrine channels. This is a channel so, you must create your own that take this channel and filter what you don't want and use your custom channel.Apprise
The resources communicated can help achieve this goal.Apprise
Please update your question title. This will avoid confusion.Apprise
Sorry, I don't understand - I think the title expresses exactly what I want - I want to turn off logging for symfony messenger component, i.e. symfony.com/doc/4.4/messenger.html. This logging is specifcally done on the doctrine channel, but any solutions targeting the entire channel are not good. Ideally, there would be a way to disable all logging coming from the messenger component, but it appears there isn't.Extension
Yup, I did, the problem is that this stuff is logged on the doctrine channel, so adding the !messenger does nothing.Extension
It why I think if you want to do this specifically, you should rewrite something from the Messenger component or Doctrine. Check how the channel is made and when log entries you don't want are added to the doctrine channel.Apprise
Check: #60492005Apprise
Let us continue this discussion in chat.Apprise
F
1

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"]
Feltner answered 8/2, 2021 at 11:15 Comment(5)
This would bascially result in having less stuff in log files altogether, but that's not what the question asked, unfortunately.Extension
All HTTP requests have one or more logs with at least INFO or higher level, so this configuration does not change anything there. For messenger workers, most of the time, they contain only Doctrine debug logs, so this configuration will avoid the spam there.Feltner
Ah, I got it now. It's a bit "sideways", but it looks like it will work, and that's what matters.Extension
Yes, clearly not the best fix, but it's the simplest fix I found without having to make too much modifications in the messenger / monolog configurationsFeltner
I've tried this out. Messenger worker works for e.g. 3600 seconds and during that time spams doctrine.DEBUG logs every second, but also messenger.INFO when handling a message and also one at the end that's like "I'm stopping". So I added !messenger to the main handler, but added another stream-handler for messenger channel to keep them in the log without triggering main. In the end, it didn't work for me because I have deprecation INFO messages which I can't easily remove on symfony 4.4. Apparently, there's a "deprecation" channel in 5.1 so I'll try this again when I upgrade.Extension

© 2022 - 2024 — McMap. All rights reserved.