Apply PSR-3 replacements in Telescope logs #1604
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why make this change?
When a log channel is configured with
'replace_placeholders' => true
or'processors' => [PsrLogMessageProcessor::class]
, a statement likeLog::info('User {user_id} logged in', ['user_id' => 1]);
is expected to produce the messageUser 1 logged in
in Telescope. However, currently, the raw messageUser {user_id} logged in
is displayed instead. This makes logs harder to read in Telescope, as one must open each individual log entry to view the context.Telescope listens for the MessageLogged event, which is dispatched in
\Illuminate\Log\Logger::writeLog
. However, this event uses the original, unformatted message. It isn’t straightforward to access the formatted message, since formatting occurs deep within the Monolog logger and its result isn’t returned.This change aims to improve log readability in Telescope when messages use placeholder replacements (as defined in PSR-3 §1.2 Message). The original message will still be preserved in the context for reference, in case it’s needed for codebase lookups.