:logger application not running on CI server (inside docker)

We are currently trying to setup gitlab CI to continuously run tests for all our branches. Unfortunately, quite a lot of them fail due to the following kind of errors:

  test description
     test/shop/shop_test.exs:134
     ** (RuntimeError) cannot use Logger, the :logger application is not running

We do not see those errors when running tests locally. The initial startup phase looks like:

The structure for Api.Repo has been loaded from /builds/prepaidticket/api/priv/repo/structure.sql
20:56:55.099 [error] Supervisor 'Elixir.Logger.Supervisor' had child 'Elixir.Logger.ErrorHandler' started with 'Elixir.Logger.Watcher':start_link({error_logger,'Elixir.Logger.ErrorHandler',{true,false,500}}) at <0.8054.0> exit with reason normal in context child_terminated
20:56:55.163 [info] Application lager started on node nonode@nohost
…
20:56:56.494 [warning] lager_error_logger_h dropped 0 messages in the last second that exceeded the limit of 50 messages/sec
20:57:03.688 [info] Application logger exited with reason: stopped
20:57:03.754 [info] Application ex_unit started on node nonode@nohost

No idea why the logger application just stops.

And then we also see errors in between like this:

=ERROR REPORT==== 23-Jul-2018::20:57:05 ===
** Generic server tzdata_release_updater terminating 
** Last message in was check_if_time_to_update
** When Server state == []
** Reason for termination == 
** {#{'__exception__' => true,'__struct__' => 'Elixir.RuntimeError',
      message =>
          <<"cannot use Logger, the :logger application is not running">>},
    [{'Elixir.Logger.Config','__data__',0,
                             [{file,"lib/logger/config.ex"},{line,53}]},
     {'Elixir.Logger',bare_log,3,[{file,"lib/logger.ex"},{line,621}]},
     {'Elixir.Tzdata.ReleaseUpdater',poll_for_update,0,
                                     [{file,"lib/tzdata/release_updater.ex"},
                                      {line,38}]},
     {'Elixir.Tzdata.ReleaseUpdater',handle_info,2,
                                     [{file,"lib/tzdata/release_updater.ex"},
                                      {line,17}]},
     {gen_server,try_dispatch,4,[{file,"gen_server.erl"},{line,616}]},
     {gen_server,handle_msg,6,[{file,"gen_server.erl"},{line,686}]},
     {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]}
20:57:05.819 [error] gen_server tzdata_release_updater terminated with reason: #{'__exception__' => true,'__struct__' => 'Elixir.RuntimeError',message => <<"cannot use Logger, the :logger application is not running">>} in 'Elixir.Logger.Config':'__data__'/0 line 53
20:57:05.819 [error] CRASH REPORT Process tzdata_release_updater with 0 neighbours crashed with reason: #{'__exception__' => true,'__struct__' => 'Elixir.RuntimeError',message => <<"cannot use Logger, the :logger application is not running">>} in 'Elixir.Logger.Config':'__data__'/0 line 53
20:57:05.820 [error] Supervisor {<0.380.0>,'Elixir.Supervisor.Default'} had child 'Elixir.Tzdata.ReleaseUpdater' started with 'Elixir.Tzdata.ReleaseUpdater':start_link() at <0.386.0> exit with reason #{'__exception__' => true,'__struct__' => 'Elixir.RuntimeError',message => <<"cannot use Logger, the :logger application is not running">>} in 'Elixir.Logger.Config':'__data__'/0 line 53 in context child_terminated

Any idea how to fix it?

Which versions of elixir and erlang are running on your CI?

I am using the official elixir docker image, so it would be elixir 1.6.6 and erlang 20.

Did you think to add the logger as a dependency of your application?
I mean in your mix.exs file add this runtime depency this way:

extra_applications: [:logger],

As he says it works locally but only fails in CI, I do assume so.

Also the output suggests that :logger gets started but then shuts down or crashes.

@namxam can you please try to use elixir 1.6.5 in CI? Can you also try 1.6.6 with OTP-21?

When you run locally, do you use the exact same versions of erlang/elixir as in CI? If not, does the problem also happens locally if you were?

I was supposing that the tests done during the CI are done on a release version. It can be the reason of the missing logger application

Ok, I found the error. I was using {:ok, _} = Application.ensure_all_started(:api) in a Mix task. Unfortunately, it stopped the logger application afterwards. I replaced it with Mix.Task.run("app.start") and the logger wont stop.

1 Like