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.
I'm not sure if this should go to
8.x
ormaster
, let me know if I should switch the target branch.Here's the commit message from the second commit (the first is just an aesthetic change to make the second commit more readable - feel free to squash if needed):
Add special handling when logging exceptions
Illuminate\Foundation\Exceptions\Handler::report()
already does this when logging caught exceptionsPreviously, logged exceptions would be passed down to
Illuminate\Monolog\Logger
which forcibly casts them to strings, resulting in the__toString()
method being called on them - which is inherited from Exception, which prints a stack trace. This stack trace ends up being used as the log message itself.This change makes it so that when an exception is logged, the log message becomes a shorter and usually more readable string, which is the return value of the
getMessage()
method on the exception object, and passes the exception object itself as theexception
key of the log message context, but only if that key wasn't already manually set by the user when logging the exception.Monolog's
LineFormatter
will already process exceptions found in the context to include a nice stack trace, if theincludeStacktraces
option is turned on (which it is by default in Laravel).This means that no information should be lost, unless someone is explicitly relying on the current behavior and/or making uncommon logging configuration changes.
Furthermore, this enables userland code to attach additional processors to the wrapped Monolog instance and include additional custom processing on the logged exception objects if desired.
Ref laravel/ideas#2449 (comment)