Timber v2.2.1 Timber.Contexts.CustomContext View Source
The CustomContext
allows you to track contextual information relevant to your
system that is not one of the commonly supported contexts for Timber (Timber.Contexts.*
).
Fields
type
- (atom, required) This is the type of your context. It should be something unique and unchanging. It will be used to identify this content. Example::my_context
.data
- (map, optional) A map of data. This can be anything that can be JSON encoded. Example:%{key: "value"}
.
Example
There are 2 ways to log custom events:
- Use a map (simplest)
Timber.add_context(%{type: :build, data: %{version: "1.0.0"}})
Use a struct
Defining structs for your contexts creates a strong contract with down stream consumers and gives you compile time guarantees. It makes a statement that this context means something and that it can relied upon.
defmodule BuildContext do
use Timber.Contexts.CustomContext, type: :build
@enforce_keys [:version]
defstruct [:version]
end
Timber.add_context(%BuildContext{version: "1.0.0"})
Link to this section Summary
Link to this section Types
Link to this type
t()
View Source
t() :: %Timber.Contexts.CustomContext{data: %{optional(String.t) => any}, type: atom}