Seldaek / monolog

Sends your logs to files, sockets, inboxes, databases and various web services
https://seldaek.github.io/monolog/
MIT License
21.02k stars 1.9k forks source link

Add ChannelAwareProcessorInterface #1421

Closed ro0NL closed 4 years ago

ro0NL commented 4 years ago

Hi!

Today we spent severe time debugging a processor :)

Intuitively we implement ProcessorInterface for its contract value, and being a core library type.

Turns out the Symfony bundle auto configures these as such, tagging them with monolog.processor

This effectively breaks https://symfony.com/doc/current/logging/processors.html#registering-processors-per-channel as it's tagged twice, thus the auto configured one has no channel causing it to be pushed to all loggers, instead of a channel specific one.

Perhaps we should have read

https://github.com/Seldaek/monolog/blob/f2d431523774cb675409669f0eec1e6cf127cc5c/src/Monolog/Processor/ProcessorInterface.php#L15

AFAIK the general purpose is type based autoconfiguration for DI, but maybe it's worth to create an additional ChannelAwareProcessorInterface for the same general purpose.

interface ChannelAwareProcessorInterface extends ProcessorInterface {
    public static function getChannels(): string[];
}

Or add it to ProcessorInterface directly even :/

Thoughts?

Seldaek commented 4 years ago

IMO this is rather a bug of the MonologBundle. If the class is already configured with a processor tag, it should not add another tag due to the class implementing that interface. Should be reported/fixed there.

Also having getChannels would not help as you want the configuration to define where the processor is used, not the processor itself.. Otherwise it becomes very tightly coupled.