0
votes

I am trying to use "Lager" ( a logger application ). Lager was started from a main application module "A"

Following is how lager was specified in the .app file:

{application, myapp,
 [
  {description, ""},
  {vsn, "1"},
  {registered, []},
  {applications, [kernel, stdlib]},
  {mod, { ontoq, []}},
  {env, [
          {lager, [
            {handlers, [
              {lager_console_backend, info},
              {lager_file_backend, [{file, "error.log"}, {level, error}]},
              {lager_file_backend, [{file, "console.log"}, {level, info}]}
            ]}
          ]}
        ]
  }
 ]}.

I do start lager from my Application "A"'s start function:

start(_StartType, _StartArgs) ->
  random:seed(erlang:now()),
  lager:start(),
  lager:info("here is something to the log ~p", ["SomeString"]),
  start_other_apps_that_call_module_B().

I have created another project module "B" that contains simply just plain erlang modules ( no applications ). From there, some of my functions attempts to write a log using lager:

lager:info("here is something to the log ~p", ["SomeString"]),

The above fails, somehow. I would have expected that "lager" is an atom that references to the registered application that is running on the ErlangVM. Somehow this does not seem to be the case. This is the failure message:

{undef,[{lager,info,["here is something to the log ~p",[["Something"]]],[]},{

Are there things that restrict an application visibility within the process tree

1
"The above fails, somehow." -- How exactly it fails? And another question: did you set parse transform for module B?Odobenus Rosmarus
The error i get is "{undef,[{lager,info,["here is something to the log ~p",[["Something"]]],[]},{...". Also, I am not using parse transform.gextra

1 Answers

1
votes

Actually for using lager:info, lager:error etc etc you need to compile your source with option {parse_transform, lager_transform}. You can set it in your module B (insert a row into B.erl)

-compile([{parse_transform, lager_transform}]).

or just pass parameter +{parse_transform, lager_transform} to erlc as described in the documentation http://erlang.org/doc/man/erlc.html