You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not sure if this is really a bug report or rather a feature request. But I noticed that some objects in the log context are not normalized like it is via the NormalizerFormatter and therefore disappear when using the JsonFormatter.
As an example, I am refering to the Symfony AuthenticatorManager that is writing a "Authenticator successful" log message after a successful authentication:
As you can see, the token disappeared. I already did a bit of investigation and noticed that in the NormalizerFormatter::normalize() method contains some logic for objects:
The JsonFormatter::normalize() doesn't contain such logic.
My guess is that objects are not serialized, because json_encode is taking care of it. However, private fields in PHP are not part of the encoded JSON and therefore the information gets lost.
My suggestion for a fix would be to add a similar logic for the JSON normalizer if the objects implements JSONSerializable or has a __toString() method. What do you think about it? I can provide a PR if this proposal sounds reasonable to you.
The text was updated successfully, but these errors were encountered:
JSONSerializable is already handled internally by json_encode, which is why there was no speical object treatment, but we need to add toString if it's present too.
Monolog version 2
Not sure if this is really a bug report or rather a feature request. But I noticed that some objects in the log context are not normalized like it is via the
NormalizerFormatter
and therefore disappear when using theJsonFormatter
.As an example, I am refering to the Symfony
AuthenticatorManager
that is writing a "Authenticator successful" log message after a successful authentication:https://github.com/symfony/symfony/blob/25c2bb1c7c2f1d1f32955c5f0365ccbfcc447137/src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php#L204
You can see there as well that the token is added to the log context (in my example it is an instance of
UsernamePasswordToken
).On successful authentication and when using the
StreamHandler
with the defaultNormalizerFormatter
, the output looks like this:And when the
JsonFormatter
is used, it looks like this:As you can see, the token disappeared. I already did a bit of investigation and noticed that in the
NormalizerFormatter::normalize()
method contains some logic for objects:monolog/src/Monolog/Formatter/NormalizerFormatter.php
Lines 189 to 207 in 100d0f1
The
JsonFormatter::normalize()
doesn't contain such logic.My guess is that objects are not serialized, because json_encode is taking care of it. However, private fields in PHP are not part of the encoded JSON and therefore the information gets lost.
My suggestion for a fix would be to add a similar logic for the JSON normalizer if the objects implements
JSONSerializable
or has a__toString()
method. What do you think about it? I can provide a PR if this proposal sounds reasonable to you.The text was updated successfully, but these errors were encountered: