Timber v1.1.10 Timber.Contextable protocol

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.

Summary

Functions

Converts the data structure into a Timber.Event.t

Types

t()
t() :: term

Functions

to_context(data)
to_context(any) :: Timber.Context.t

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