4

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.

knezmilos
  • 517
  • 1
  • 8
  • 19
  • 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. – LBA Aug 24 '20 at 14:46
  • plus you could increase the log level to avoid seeing debug messages - or you could use ["fingers crossed"](https://symfony.com/doc/current/logging.html#handlers-that-modify-log-entries) 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? – LBA Aug 24 '20 at 14:52
  • @LBA 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. – knezmilos Aug 24 '20 at 14:59

3 Answers3

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

SwissLoop
  • 466
  • 2
  • 11
  • 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. – knezmilos Aug 25 '20 at 07:26
  • 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. – SwissLoop Aug 25 '20 at 08:50
  • The resources communicated can help achieve this goal. – SwissLoop Aug 25 '20 at 09:03
  • Please update your question title. This will avoid confusion. – SwissLoop Aug 25 '20 at 09:06
  • 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. https://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. – knezmilos Aug 25 '20 at 09:56
  • Yup, I did, the problem is that this stuff is logged on the doctrine channel, so adding the !messenger does nothing. – knezmilos Aug 25 '20 at 10:10
  • 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. – SwissLoop Aug 25 '20 at 10:13
  • Check: https://stackoverflow.com/questions/60491505/how-disable-log-info-on-middleware-of-symfony-messenger – SwissLoop Aug 25 '20 at 10:27
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/220419/discussion-between-s-lt-and-knezmilos). – SwissLoop Aug 25 '20 at 10:31
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"]
Pyrech
  • 593
  • 1
  • 4
  • 14
  • This would bascially result in having less stuff in log files altogether, but that's not what the question asked, unfortunately. – knezmilos Feb 08 '21 at 11:27
  • 1
    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. – Pyrech Feb 08 '21 at 11:44
  • Ah, I got it now. It's a bit "sideways", but it looks like it will work, and that's what matters. – knezmilos Feb 08 '21 at 13:51
  • 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 configurations – Pyrech Feb 08 '21 at 14:25
  • 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. – knezmilos Mar 10 '21 at 07:25
1

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

Dany Des
  • 41
  • 3