Timber v3.1.2 Timber.Formatter View Source

Provides utilities for formatting log lines as JSON text

This formatter is designed for use with the default :console backend provided by Elixir Logger. To use this, you'll need to configure the console backend to call the Timber.Formatter.format/4 function instead of its default formatting function. This is done with a simple configuration change. You'll also need to let :console know that :all metadata keys should be passed to the formatter.

The result of the configuration looks like:

config :logger, backends: [:console]
config :logger, :console,
  format: {Timber.Formatter, :format},
  metadata: :all

Further configuration options available on this module are documented below.

Configuration Recommendations: Development vs. Production

In a standard Elixir project, you will probably have different configuration files for your development and production setups. These configuration files typically take the form of config/dev.exs and config/prod.exs which override defaults set in config/config.exs.

Timber's defaults are production ready, but the production settings also assume that you'll be viewing the logs through the Timber console, so they forego some niceties that help when developing locally. Therefore, we recommend that you only include the Timber.Formatter in your production environments.

Transport Configuration Options

The following options are available when configuring the formatter:

escape_new_lines

When true, new lines characters are escaped as \n.

When false, new lines characters are left alone.

This circumvents issues with output devices (like Heroku Logplex) that will tranform line breaks into multiple log lines.

The default depends on on the environment variable HEROKU. If the environment variable is present, this will be set to true. Otherwise, this defaults to false. Setting the value in your application configuration will always override the initialized setting.

Link to this section Summary

Functions

Handles formatting a log for the Logger application

Link to this section Types

Link to this type

configuration() View Source
configuration() :: %{escape_new_lines: boolean()}

Link to this section Functions

Link to this function

format(level, message, ts, metadata) View Source

Handles formatting a log for the Logger application

This function allows you to integrate Timber with the default :console backend distributed with the Elixir Logger application. By default, lines are printed as encoded JSON strings,.