Custom Logger backend dependency issue on releases

I’ve written a custom Logger backend that logs stuff in Rollbar, using the library Rollbax and I’m not able to make it work using distillery releases.

This is the implementation of the logger backend:

This is the config file

config :logger,
  level: :info,
  backends: [:console, {RollbaxLoggerBackend, :rollbar_logger}],
  utc_log: true

config :logger, :rollbar_logger, level: :warn

An example of the code that fails in the release (running it through bin/my_app remote_console)

require Logger

Logger.warn("this shoud be sent to Rollbar")

This is the error I get:

(Rollbax) Trying to report an exception but the :rollbax application has not been started

I checked the started applications and rollbax was there. On top of that, explicitly doing

Rollbax.report_message("this should go to Rollbar")

works perfectly fine.

I guess there must be something about how the logger backends work that I’m missing. Does anyone have any hint?

The question. Does the error shows before your Logger.warn/1 call or after? Because if this is before, then probably the problem is that Rollbax also is using Logger so you end with sending messages to Rollbax before it start. Instead I would suggest you to add handler in your Application.start/2 callback and this should remove the error.

1 Like

Thanks for the answer. That’s a good point and I guess it could be problematic, but the error shows after I run Logger.warn/1, not before.