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

LogRecord->with does not transfers "formatted" value #1788

Open
Justinas-Jurciukonis opened this issue Jan 17, 2023 · 4 comments
Open

LogRecord->with does not transfers "formatted" value #1788

Justinas-Jurciukonis opened this issue Jan 17, 2023 · 4 comments
Labels
Milestone

Comments

@Justinas-Jurciukonis
Copy link

Justinas-Jurciukonis commented Jan 17, 2023

Monolog version 3.2.0

When PsrLogMessageProcessor processes message, it returns new instance of LogRecord using code

return $record->with(message: strtr($record->message, $replacements), context: $context);

and inside LogRecord->with there is missing formatted key to be copied over, so if any previous processor set any information inside LogRecord->formatted it will be lost.

Seems like same issue with toArray

@Seldaek
Copy link
Owner

Seldaek commented Feb 4, 2023

Normally formatting happens after processing, so this should never be a problem. Have you experienced an actual issue?

@Seldaek Seldaek added this to the 3.x milestone Feb 4, 2023
@Justinas-Jurciukonis
Copy link
Author

@Seldaek Yes, since we use custom logic to format all records.

Basically logic was as follows:

  1. Create new structure to formatted property
  2. Every processor adds it's own information to this formatted to the place where it needs to be
  3. Formatter converts log record to JSON or Plain text log, but keeps structure from formatted. Means formatters only responsible for final output, but not structure of log itself

With this approach formatters does not care about structure, just how format LogRecord to string. Processors are responsible for it's own parts of LogRecord->formatted processing.

E.g. Adding information about current user can come from 3 different processors and it merges under key LogRecord->formatted->user

@stof
Copy link
Contributor

stof commented Feb 6, 2023

This looks like the use case for LogRecord->extra instead

@Seldaek
Copy link
Owner

Seldaek commented Feb 7, 2023

Right, exactly my thinking @stof - sounds to me like these processors should all record stuff in extra as they are meant to, and then the final formatter can use the info in context/extra to generate the final formatted record.

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

No branches or pull requests

3 participants