monolog-bundle
monolog-bundle copied to clipboard
Processors implementing ProcessorInterface ignore handler/channel setting
Symfony version(s) affected: 5.0.5
Description
Processors implementing \Monolog\Processor\ProcessorInterface ignore handler/channel setting and are being invoked for every handler/channel.
How to reproduce
Can be reproduced with example from official documentation https://symfony.com/doc/current/reference/dic_tags.html#monolog-processor
services:
Monolog\Processor\IntrospectionProcessor:
tags:
- { name: monolog.processor, handler: firephp }
This will add extra for every handler you have in monolog.yaml
Possible Solution
https://github.com/symfony/monolog-bundle/blob/master/DependencyInjection/MonologExtension.php#L123
Here it adds tag monolog.processor so processor applies to every handler/channel.
Looks like autoconfigure: false is service definition does the job and example starts working, but only for my own classes, not for default processors like \Monolog\Processor\IntrospectionProcessor
but only for my own classes, not for default processors like \Monolog\Processor\IntrospectionProcessor
I don't understand what you mean. It shouldn't matter which class is used. It only matters if the service enabled autoconfigure or not. If enabled it prevents using a processor for a specific handler as you figured out.
Any updates? It is reproduced in symfony 6.1
DI set empty array in tags for Processors that implemented ProcessorInterface, and when walking throw processor's tags in AddProcessorsPass class, it enable for all handlers/channels.
My temporary solution, copy paste code from preset processors to my own class in app namespace. Of course without ProcessorInterface implementing.
App\Monolog\Processors\MemoryUsageProcessor:
tags:
- { name: monolog.processor, handler: with_memory }
UPD. After 15 mins i understood what's wrong) So the issue is in autoconfigure: false, it try to configure service by parent interface. Now my solution now looks next:
Monolog\Processor\MemoryUsageProcessor:
autoconfigure: false
tags:
- { name: monolog.processor, handler: with_memory }
And it works properly i want, in main handler record without extra data, but in dedicated handler going with memory data.