Timber v3.0.0-alpha.2 Timber.Eventable protocol View Source
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.
Link to this section Summary
Functions
Converts the data structure into a Timber.Event.t
Link to this section Types
Link to this section Functions
Converts the data structure into a Timber.Event.t
.