Timber v2.0.0-rc1 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.CustomEvent
in that module.
This takes care of everything automatically. See Timber.Events.CustomEvent
for examples.
Summary
Functions
Converts the data structure into a Timber.Event.t
Types
Functions
Converts the data structure into a Timber.Event.t
.