Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not logging to file #63

Closed
madtrick opened this issue Jul 14, 2012 · 2 comments
Closed

Not logging to file #63

madtrick opened this issue Jul 14, 2012 · 2 comments

Comments

@madtrick
Copy link

Hi,

I have just started to play with Lager so probably I'm doing something but I'm no able to log to file.

My setup:

  • I have included the lager_transform directive in rebar.config

  • I have copied the lager app config to my app.config

    [
    {lager, [
      {handlers, [
        {lager_console_backend, info},
        {lager_file_backend, [
          {"info.log", info, 0, "", 5},
          {"debug.log", debug, 0, "", 5}
        ]}
      ]}
    ]}
    ].
  • Inside my code I have several calls to lager

    handle_cast(_, State) ->
    %lager:error("Error msg"),
    lager:info("Info msg"),
    lager:debug("Debug msg"),
    lager:warning("Warming msg"),
    {noreply, State}.

I have an escript script to run a quick test:

 main(_) ->
  inets:start(),
  lager:start(),
  {ok, Worker} = qrauth_worker:start_link(),
  qrauth_worker:request(Worker).

Inside qrauth_worker:request/1 I do a gen_server:cast which is handled by the code above.

When I run the escript this is the output in the console:

>>./worker 
11:07:35.394 [info] Application lager started on node nonode@nohost
11:07:35.399 [info] Application amqp_client started on node nonode@nohost
11:07:35.443 [info] Info msg
11:07:35.443 [warning] Warming msg

Which is the expected output according to my lager statements and my lager config.

But my info.log and debug.log files are empty.

To make things a bit more weird for me, if I include a lager:error statement this one flushes the log to the files but fails to output the error msg to the console.

This is the code with the lager:error

handle_cast(_, State) ->
  lager:info("Info msg"),
  lager:debug("Debug msg"),
  lager:warning("Warming msg"),
  lager:error("Error msg"),
  {noreply, State}.

This is the console output

>>./worker 
11:07:35.394 [info] Application lager started on node nonode@nohost
11:07:35.399 [info] Application amqp_client started on node nonode@nohost
11:07:35.443 [info] Info msg
11:07:35.443 [warning] Warming msg

Notice that the [error] log is missing in the console output

And this is my info.log

>>cat info.log 
2012-07-14 11:17:24.379 [info] <0.6.0> Application lager started on node nonode@nohost
2012-07-14 11:17:24.384 [info] <0.6.0> Application amqp_client started on node nonode@nohost
2012-07-14 11:17:24.424 [info] <0.75.0>@qrauth_worker:init:62 Starting worker
2012-07-14 11:17:24.434 [info] <0.75.0>@qrauth_worker:handle_cast:93 Info msg
2012-07-14 11:17:24.434 [warning] <0.75.0>@qrauth_worker:handle_cast:95 Warming msg
2012-07-14 11:17:24.435 [error] <0.75.0>@qrauth_worker:handle_cast:96 Error msg

Any hints or ideas. Thanks

@Vagabond
Copy link
Member

My best guess is that your escript is exiting before everything is flushed to disk and/or the console. The [error] loglevel forces a fdatasync, so that is why it makes your logs suddenly work, but there's no way to force a flush to the console.

@Vagabond
Copy link
Member

Closing due to inactivity.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants