While testing my custom logger handler, which is based on the Sentry Elixir handler, I encountered an issue where passing a struct to Logger.error causes the handler to detach. The error handler only supports keywords and maps.
The problem arose when using the Tesla library, which passes a Tesla.Env struct to Logger.error. Interestingly, Logger.info does support passing structs, and the struct is displayed as a keyword list or map with the __struct__field
iex(3)> Logger.error(%Foo{})
:ok
23:36:43.117 [error] [__struct__: Foo, bar: nil]
I added a test that reproduce the issue and a fix proposition.
👋
While testing my custom logger handler, which is based on the Sentry Elixir handler, I encountered an issue where passing a struct to
Logger.error
causes the handler to detach. The error handler only supports keywords and maps.The problem arose when using the Tesla library, which passes a
Tesla.Env
struct toLogger.error
. Interestingly,Logger.info
does support passing structs, and the struct is displayed as a keyword list or map with the__struct__
fieldI added a test that reproduce the issue and a fix proposition.