Timber v1.1.10 Timber.Transport behaviour

A Transport specifies the way in which Timber.LoggerBackend should actually output log events.

While the Timber.LoggerBackend module will handle receiving and processing log events, the process of actually outputting them is left to the trasnport. The transport is also responsible for managing any necessary buffers and switching between syncrhonous and asynchronous output.

Summary

Types

The transport state can be used to keep track of stateful data for operations, such as buffers and process IDs. It will always be passed as the final parameter to any expected callback and is expected to be returned by the function

Callbacks

Passes configuration changes to the transport

Flushes pending messages from any buffer

Handles handle_info process messaging forwarded from Timber.LoggerBackend

Initializes the transport

Writes a log message to the transport

Types

state()
state() :: any

The transport state can be used to keep track of stateful data for operations, such as buffers and process IDs. It will always be passed as the final parameter to any expected callback and is expected to be returned by the function.

Callbacks

configure(options, state)
configure(options :: Keyword.t, state) ::
  {:ok, state} |
  {:error, Exception.t}

Passes configuration changes to the transport

The transport is expected to store any configuration on the state it passes back.

flush(state)
flush(state) :: state

Flushes pending messages from any buffer

If your transport implements a buffer, this call should essentially be synchronous, blocking until all messages in the buffer have been sent and confirmed output.

handle_info(info, state)
handle_info(info :: tuple, state) :: {:ok, state} | no_return

Handles handle_info process messaging forwarded from Timber.LoggerBackend

It is expected that your transport at least return {:ok, state} for any given info.

init()
init() :: {:ok, state} | no_return

Initializes the transport

The transport is expected to start any necessary processes at this point. References to other processes should be kept in the state which is then returned.

write(arg0, state)
write(Timber.LogEntry.t, state) :: {:ok, state} | no_return

Writes a log message to the transport

The log entry to write will be sent along with the state. Writing the log entry is not expected to be immediate, but this function is expected to return quickly. If the transport uses a buffer, that buffer should be maintained in the state which is then returned.