This MR now primarily contains a bugfix for logging raised and caught exceptions :)
Click here for the original description of this MR
When using the Elastic logger in my work project, I noticed that the logging flow for caught exceptions is not very smooth, as I first have to call `Logger.metadata(crash_reason: e)` (where `e` is my caught exception) to save the error context before every `Logger.warning` or `Logger.error` or the like. Even worse, as a caller and especially someone inexperienced with `Logger`, there's no indication as to the lifetime of whatever is passed to `Logger.metadata`. Will it stay there until the next log, will it be included in every log from that point on? (spoiler alert, it's the latter, so you'd need to manually clear the crash reason in the metadata after the log).
tl;dr: this replaces
```elixir
try do
raise "oops"
rescue
e in RuntimeError ->
Logger.metadata(crash_reason: e)
Logger.error("Something went wrong")
Logger.metadata(crash_reason: nil)
end
```
```elixir
try do
raise "oops"
rescue
e in RuntimeError -> Logger.error("Something went wrong", crash_reason: e)
end
```
coverage: 100.0%. remained the same
when pulling a06ba99efcc555e0e8300189fa8a2dcd75185635 on bvobart:master
into 24320817eea9739238bddf1711cf2d32e0f0c6b0 on Nebo15:master.
Hi again :)
This MR now primarily contains a bugfix for logging raised and caught exceptions :)
Click here for the original description of this MR
When using the Elastic logger in my work project, I noticed that the logging flow for caught exceptions is not very smooth, as I first have to call `Logger.metadata(crash_reason: e)` (where `e` is my caught exception) to save the error context before every `Logger.warning` or `Logger.error` or the like. Even worse, as a caller and especially someone inexperienced with `Logger`, there's no indication as to the lifetime of whatever is passed to `Logger.metadata`. Will it stay there until the next log, will it be included in every log from that point on? (spoiler alert, it's the latter, so you'd need to manually clear the crash reason in the metadata after the log). tl;dr: this replaces ```elixir try do raise "oops" rescue e in RuntimeError -> Logger.metadata(crash_reason: e) Logger.error("Something went wrong") Logger.metadata(crash_reason: nil) end ``` ```elixir try do raise "oops" rescue e in RuntimeError -> Logger.error("Something went wrong", crash_reason: e) end ```