Skip to content

Conversation

HypeMC
Copy link
Member

@HypeMC HypeMC commented Aug 30, 2025

Similar to symfony/symfony#61526.

When you add a custom processor to a specific channel or handler, it gets added to all channels because ProcessorInterface is registered for autoconfiguration.

Here's a simple example:

#[AsMonologProcessor('my_channel')]
final class MyProcessor implements ProcessorInterface
{
    public function __invoke(LogRecord $record) {}
}

You'd expect this processor to be registered only for my_channel, but due to autoconfiguration it's added to every channel.

The workaround is to disable autoconfiguration and add an explicit tag.

services:
    App\MyProcessor:
        autoconfigure: false
        tags:
            - monolog.processor: { channel: 'my_channel' }

This PR ensures a processor is not added to all channels when an explicit channel or handler is configured.

@HypeMC
Copy link
Member Author

HypeMC commented Aug 30, 2025

CI failure is false positive, trailing_comma_in_multiline is not supported in PHP 7.2.

@GromNaN GromNaN added the Feature label Sep 5, 2025
@HypeMC HypeMC force-pushed the fix-autoconfigure-processor branch from 8e5202a to fa17522 Compare September 5, 2025 22:36
@HypeMC HypeMC force-pushed the fix-autoconfigure-processor branch from fa17522 to b8070aa Compare September 5, 2025 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants