Timber v3.0.0-alpha.2 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 Keyword.t types:

Timber.add_context(build: %{version: "1.0"})

This is achieved by:

defimpl Timber.Contextable, for: Map do
  def to_context(map) when map_size(map) == 1 do
    [type] = Map.keys(map)
    [data] = Map.values(map)
    %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

Link to this function to_context(data) View Source
to_context(map() | list()) :: Timber.Context.element()

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