timber-elixir icon indicating copy to clipboard operation
timber-elixir copied to clipboard

Adds `to_event` support for arbitrary structs

Open jmnsf opened this issue 6 years ago • 1 comments

Adds the ability to send structs as events in log metadata:

Logger.info("Something happened", event: %AnEvent{with_data: true})

Right now, doing this raises an exception and the log message is dropped:

(FunctionClauseError) no function clause matching in Timber.Eventable.Any.to_event/1

Use case

I'm using struct events in my project to represent something happening in the app and its associated data. In the event handler for those events, I'm adding the event itself as context to all logging. It doesn't work though, because Timber can't convert it.

This PR uses the struct name as the context namespace for its logged contents.

jmnsf avatar Nov 28 '19 17:11 jmnsf

Pull Request Test Coverage Report for Build 915

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.4%) to 42.373%

Totals Coverage Status
Change from base Build 885: 0.4%
Covered Lines: 200
Relevant Lines: 472

💛 - Coveralls

coveralls avatar Nov 28 '19 17:11 coveralls