Skip to content

Apply PSR-3 replacements in Telescope logs #1604

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

Merged
merged 6 commits into from
Jul 2, 2025

Conversation

DragosMocrii
Copy link
Contributor

@DragosMocrii DragosMocrii commented Jul 1, 2025

Why make this change?

When a log channel is configured with 'replace_placeholders' => true or 'processors' => [PsrLogMessageProcessor::class], a statement like Log::info('User {user_id} logged in', ['user_id' => 1]); is expected to produce the message User 1 logged in in Telescope. However, currently, the raw message User {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.

image

Copy link

github-actions bot commented Jul 1, 2025

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@DragosMocrii DragosMocrii changed the title 5.x Apply PSR-3 replacements in Telescope logs Jul 1, 2025
@DragosMocrii DragosMocrii marked this pull request as ready for review July 1, 2025 18:15
@taylorotwell taylorotwell merged commit 6933494 into laravel:5.x Jul 2, 2025
16 checks passed
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.

2 participants