Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add priority field to processor tags #455

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sudo-plz
Copy link

@sudo-plz sudo-plz commented Mar 17, 2023

So that the order in which the processors are used by monolog can be determined.
Example config:

Foo\Bar\Log\Processors\FirstProcessor:
    tags:
        - { name: monolog.processor, channel: http }

Foo\Bar\Log\Processors\SecondProcessor:
    tags:
        - { name: monolog.processor, channel: http, priority: -10 } # last

Foo\Bar\Log\Processors\ThirdProcessor:
    tags:
        - { name: monolog.processor, channel: http, priority: -20 } # very last

(PR in favor of old PR)

So that the order in which the processors are used by monolog can be
determined.
foreach ($container->findTaggedServiceIds('monolog.processor') as $id => $tags) {
foreach ($tags as $tag) {
if (!empty($tag['channel']) && !empty($tag['handler'])) {
throw new \InvalidArgumentException(sprintf('you cannot specify both the "handler" and "channel" attributes for the "monolog.processor" tag on service "%s"', $id));
if (!isset($tag['priority'])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the priority option also be added to #[AsMonologProcessor] ?

Copy link
Author

Choose a reason for hiding this comment

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

I should be able to add it without a problem, thanks for the suggestion!

Copy link
Author

Choose a reason for hiding this comment

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

Update: 1797

Comment on lines +49 to +53
usort(
$processors,
function (array $left, array $right) {
return $left['tag']['priority'] <=> $right['tag']['priority'];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the PriorityTaggedServiceTrait be used here?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, however the PriorityTaggedServiceTrait can´t be used since it will require some changes because the Trait sorts it ascending (as expected). But monologs pushProcessor actually array_shifts instead of adding it on top of the stack, so I need a descending sort. Which is clarified in the comment.

Copy link
Member

Choose a reason for hiding this comment

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

We could still use the trait to get the sorted services and reverse the list before adding method calls.

Seldaek pushed a commit to Seldaek/monolog that referenced this pull request Jun 20, 2023
@sudo-plz
Copy link
Author

Related PR has been merged, can you finish the review @HypeMC? Thanks!

@nicklog
Copy link

nicklog commented Dec 28, 2023

Hey, what's the status here? I'm also interested in the feature. Thanks :)

@sudo-plz
Copy link
Author

Hey, what's the status here? I'm also interested in the feature. Thanks :)

Following comment is still open: https://github.com/symfony/monolog-bundle/pull/455/files#r1369858964
I didn't take the time to fix it anymore, however I'll check if I can implement it sometime (or feel free to change it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants