Timber v2.0.0-rc5 Timber.LoggerBackends.HTTP

Provides a logger backend that dispatches logs via HTTP

The HTTP backend buffers and delivers log messages over HTTP to the Timber API. It uses batching and msgpack to deliver logs with high-throughput and little overhead.

Messages are always written to the buffer first. The buffer is only drained when it reaches its maximum allowed size or a specified amount of time has elapsed. This balances output with batching so that logs are sent even when the application doesn’t produce enough logs to fill the buffer.

The maximum allowed size of the buffer can be controlled with the :max_buffer_size configuration value.

All outgoing requests are made asynchronously. If a second request is made while the previous (first) request is still being processed, then the transport will enter synchronous mode, waiting for a response before proceeding with the request. Synchronous mode will cause any logging calls to block until the request completes.

Configuration

Custom HTTP client

The HTTP backend can use any HTTP client, so long as it supports asynchronous requests. Suport for :hackney is built into the library and is the default client, supported via Timber.Transports.HTTP.HackneyClient. You can define your own custom HTTP client by adhering to the Timber.Transports.HTTP.Client behaviour. Afterwards, you must specify your client in the configuration:

config :timber, :http_client, MyHTTPClient

Summary

Types

The level of a log event is described as an atom

The message for a log event is given as IO.chardata. It is important not to assume the message will be a String.t/0

The precision of the microsecond represents the precision with which the fractional seconds are kept

t()

A representation of stateful data for this module

Time is represented both to the millisecond and to the microsecond with precision

Types

buffer()
buffer() :: [] | [IO.chardata]
date()
date() :: {year, month, day}
day()
day() :: 1..31
hour()
hour() :: 0..23
level()
level() :: Logger.level

The level of a log event is described as an atom

message()
message() :: IO.chardata

The message for a log event is given as IO.chardata. It is important not to assume the message will be a String.t/0

microsecond()
microsecond() :: 0..999999
millisecond()
millisecond() :: 0..999
minute()
minute() :: 0..59
month()
month() :: 1..12
precision()
precision() :: 0..6

The precision of the microsecond represents the precision with which the fractional seconds are kept.

See Calendar.microsecond/0 for more information.

second()
second() :: 0..59
t()
t() :: %Timber.LoggerBackends.HTTP{api_key: String.t, buffer: buffer, buffer_size: non_neg_integer, flush_interval: non_neg_integer, http_client: term, max_buffer_size: pos_integer, min_level: level | nil, ref: reference}

A representation of stateful data for this module

min_level

The minimum level to be logged. The Elixir Logger module typically handle filtering the log level, however this is a stop-gap for direct testing as well as any custom levels.

Time is represented both to the millisecond and to the microsecond with precision.

timestamp()
timestamp() :: {date, time}
year()
year() :: pos_integer