Timber v3.0.0-alpha.2 Timber View Source

The functions in this module are high level convenience functions instended to define the broader / public API of the Timber library. It is recommended to use these functions instead of their deeper counterparts.

Link to this section Summary

Types

The target context to perform the operation

Functions

Adds context which will be included on log entries

Captures the duration in fractional milliseconds since the timer was started. See start_timer/0

Used to time runtime execution. For example, when timing a Timber.Events.HTTPResponseEvent

Link to this section Types

Link to this type context_location() View Source
context_location() :: :local | :global

The target context to perform the operation.

  • :global - This stores the context at a global level, meaning it will be present on every log line, regardless of which process generates the log line.
  • :local - This stores the context in the Logger Metadata which is local to the process

Link to this section Functions

Link to this function add_context(data, location \\ :local) View Source
add_context(Timber.Context.element(), context_location()) :: :ok

Adds context which will be included on log entries

The second parameter indicates where you want the context to be stored. See context_location for more details.

Captures the duration in fractional milliseconds since the timer was started. See start_timer/0.

Link to this function remove_context_key(key, location \\ :local) View Source
remove_context_key(atom(), context_location()) :: :ok

Removes a context key.

The second parameter indicates which context you want the key to be removed from.

Used to time runtime execution. For example, when timing a Timber.Events.HTTPResponseEvent:

timer = Timber.start_timer()
# .... make request
time_ms = Timber.duration_ms(timer)
event = HTTPResponseEvent.new(status: 200, time_ms: time_ms)
message = HTTPResponseEvent.message(event)
Logger.info(message, event: event)