Timber v1.0.2 Timber.Eventable protocol

Converts a data structure into a Timber.Event.t. This is called on any data structure passed in the :event metadata key passed to Logger.

For example, this protocol is how we’re able to support maps:

event_data = %{customer_id: “xiaus1934”, amount: 1900, currency: “USD”} Logger.info “Payment rejected”, event: event_data

This is achieved by:

defimpl Timber.Eventable, for: Map do

def to_event(%{type: type, data: data}) do
  %Timber.Events.CustomEvent{
    type: type,
    data: data
  }
end

end

What about custom events and structs?

We recommend defining a struct and calling use Timber.Events.Custom in that module. This takes care of everything automatically. See Timber.Events.Custom for examples.

Summary

Functions

Converts the data structure into a Timber.Event.t

Types

t()
t :: term

Functions

to_event(data)
to_event(any) :: t

Converts the data structure into a Timber.Event.t.