Home

Awesome

LoggerLagerBackend

A lager (https://github.com/erlang-lager/lager) backend for Elixir's Logger (https://hexdocs.pm/logger/Logger.html).

That is, it routes messages generated with Logger.<level>() to lager. This is useful if you have a mixed Erlang/Elixir project and have decided to standardize on lager as a logging framework.

Known limitations:

Installation

Add logger_lager_backend to your list of dependencies in mix.exs:

def deps do
  [{:logger_lager_backend, "~> 0.1.0"}]
end

Configuration

Instruct Logger to use logger_lager_backend:

config :logger,
  backends: [LoggerLagerBackend],
  handle_otp_reports: false,
  level: :debug

This sends all messages of level debug or higher to lager. They will then be subject to filtering and routing according to whichever lager config you have in place.

We also use handle_otp_reports: false to avoid having messages from the Erlang's built-in error_logger module appear twice in the output.

Troubleshooting

FORMAT ERRORs in log

If you get FORMAT ERROR messages like this one:

FORMAT ERROR: "~s" [[<<"GenServer :redis_sub_0_8 terminating">>,<<"\n** (stop) ">>|<<":redis_down">>]

You're probably hitting erlang-lager/lager#326. Upgrade lager to 3.2.0 or more recent.

Elixir.Logger.Supervisor error on startup

If you get the following message on startup:

[error] Supervisor 'Elixir.Logger.Supervisor' had child 'Elixir.Logger.ErrorHandler' started with
  'Elixir.Logger.Watcher':watcher(error_logger, 'Elixir.Logger.ErrorHandler',
  {true,false,500}, link) at <0.422.0> exit with reason normal in context child_terminated

Make sure the :lager application is started before :logger, by putting :lager first in your applications list in mix.exs:

def application do
  [applications: [:lager, :logger, …],
   mod: {MyApp, []}]
end

Related projects