Timber v3.1.2 Timber.Eventable protocol View Source
Protocol that converts a data structure into a Timber.Event.t
.
This is called on any data structure used in the :event
metadata key passed to Logger
calls.
Example
For example, you can use this protocol to pass format event structs:
defmodule OrderPlacedEvent do
defstruct [:order_id, :total]
defimpl Timber.Eventable do
def to_event(event) do
map = Map.from_struct(event)
%{order_placed: map}
end
end
end
Then you can use it like so:
Logger.info(fn ->
event = %OrderPlacedEvent{order_id: "abcd", total: 100.23}
message = "Order #{event.id} placed"
{message, event: event}
end)
Link to this section Summary
Functions
Converts the data structure into a Timber.Event.t
Link to this section Types
Link to this type
t()
View Source
t()
View Source
t() :: term()
t() :: term()
Link to this section Functions
Link to this function
to_event(data) View Source
Converts the data structure into a Timber.Event.t
.