Skip to content

Don't add processor to all loggers if tags specify a channel or handler - #513

Merged
GromNaN merged 1 commit into
symfony:3.xfrom
HypeMC:fix-autoconfigure-processor
Sep 24, 2025
Merged

GromNaN merged 1 commit into
symfony:3.xfrom
HypeMC:fix-autoconfigure-processor

Conversation

@HypeMC

@HypeMC HypeMC commented Aug 30, 2025

Copy link
Copy Markdown
Member

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

HypeMC commented Aug 30, 2025 •

Copy link
Copy Markdown
Member Author

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

Decided to put in in one line instead.

@GromNaN GromNaN added the Feature label Sep 5, 2025
@HypeMC
HypeMC force-pushed the fix-autoconfigure-processor branch 2 times, most recently from fa17522 to b8070aa Compare September 5, 2025 22:46
@GromNaN
GromNaN changed the base branch from 4.x to 3.x September 24, 2025 10:41

@GromNaN GromNaN left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
@HypeMC can you rebase the PR on 3.x?

Comment thread Tests/DependencyInjection/Compiler/AddProcessorsPassTest.php Outdated
@HypeMC
HypeMC force-pushed the fix-autoconfigure-processor branch 2 times, most recently from 5711cf8 to e4a6633 Compare September 24, 2025 13:11
@GromNaN
GromNaN force-pushed the fix-autoconfigure-processor branch from e4a6633 to 09b4bae Compare September 24, 2025 13:45
@GromNaN

GromNaN commented Sep 24, 2025

Copy link
Copy Markdown
Member

Thank you @HypeMC.

@GromNaN
GromNaN merged commit 9fd6e45 into symfony:3.x Sep 24, 2025
11 checks passed
@HypeMC
HypeMC deleted the fix-autoconfigure-processor branch September 24, 2025 13:52
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