Skip to content

Enable PsrLogMessageProcessor on MonologHandler #293

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

Closed
wants to merge 1 commit into from

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Jan 8, 2020

This will make sure that parameters inside a log record string are interpolated with the values from the context.

Because Sentry reports like this are not very useful:

Payment failed with {exception}. Message: {message}

Also, everything that is logged as context will not be sent to Sentry at all... seems like a different issue.

@@ -58,6 +58,11 @@
<argument type="service" id="Sentry\State\HubInterface" />
<argument key="$level" />
<argument key="$bubble" />
<call method="pushProcessor">
<argument>
<service class="Monolog\Processor\PsrLogMessageProcessor" public="false"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

This has to be declared as a service somewhere else to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, PHPStorm read the XSD and showed this was possible. I was also a bit surprised by this ;) Changed it.

This will make sure that parameters inside a log record string are interpolated with the values from the context.
@guilliamxavier
Copy link
Contributor

Maybe playing the devil's advocate here, but... What if you don't want this processor to be added?

For reference, Symfony MonologBundle adds it by default (except for type: service handlers), but allows you to prevent that with the process_psr_3_messages: false per-handler option.

As for SentryBundle, currently it doesn't add it by default, but you can add it to the sentry handler with

services:
    Monolog\Processor\PsrLogMessageProcessor:
        tags: { name: monolog.processor, handler: sentry }

(assuming the current documented configuration).

Now, if it starts adding it by default, how will you be able to prevent that?

@ruudk
Copy link
Contributor Author

ruudk commented Jan 9, 2020

@guilliamxavier Wow, that's really clever :) I was not aware that it was possible like this.

I will try this out first, to see if it solves it. If it does, I'll update the docs to explain this to others.

@ruudk
Copy link
Contributor Author

ruudk commented Jan 9, 2020

Works, created a PR #295

@ruudk ruudk closed this Jan 9, 2020
@ruudk ruudk deleted the patch-2 branch January 9, 2020 13:59
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.

3 participants