Timber v2.2.1 Timber.Contextable protocol View Source
Converts a data structure into a Timber.Context.t
. This is called on any data structure passed
in the Timber.add_context/1
function.
For example, this protocol is how we’re able to support maps:
context_data = %{type: :build, data: %{version: "1.0"}}
Timber.add_context(context_data)
This is achieved by:
defimpl Timber.Contextable, for: Map do
def to_context(%{type: type, data: data}) do
%Timber.Contexts.CustomContext{
type: type,
data: data
}
end
end
What about custom contexts and structs?
We recommend defining a struct and calling use Timber.Contexts.CustomContext
in that module.
This takes care of everything automatically. See Timber.Contexts.CustomContext
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
.