Add a Monolog log formatter optimized for CloudWatch#1969
Merged
Conversation
mnapoli
added a commit
to brefphp/laravel-bridge
that referenced
this pull request
Jun 14, 2025
This was referenced Jun 14, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Edit: moved the class to https://github.com/brefphp/monolog-bridge
TODO:
bref/monolog-bridgelaravel-bridge#184bref/monolog-bridgesymfony-bridge#70The goal of this is to improve the overall logs experience with CloudWatch.
The usual format is to log unstructured text. This sucks because:
Here's an example:
A better approach is to switch to JSON-formatted logs:
But this isn't perfect:
Here's an example (Bref Cloud formats the JSON payload FYI):
CloudWatch has some great feature though:
The log message above will automatically get parsed as text (the first part) and a JSON object attached (the second part).
That means we can have a simple log message + a structured JSON object.
On top of that, with CloudWatch:
This is why I want to add this
CloudWatchFormatteroptimized for Bref users.As you can see in the screenshots below, it is easy to navigate the logs textually. But it's also possible to have a lot more information nested in the log records via the JSON object.
In CloudWatch:
In Bref Cloud:
In CloudWatch Logs Insights, we can see that keys of the JSON objects are correctly detected:
That allows us to create advanced queries, for example to search for "ERROR" logs with a specific exception class:
Looking forward
I'm releasing this in Bref v2 so that we can all test this. If this works as well as I hope, the plan is to make this the default format in Laravel with the Bref-Laravel bridge.
I am also working on a v2 for https://github.com/brefphp/logger that uses the same format: brefphp/logger#11