[erlang-questions] Integrating lager into our app

Sean Cribbs seancribbs@REDACTED
Thu Jan 21 16:12:25 CET 2016


What the message is telling you is that lager:debug() is not a function.
Indeed, if you read the source of the lager module, it is not.

The parse_transform is needed to inject code into the spot where you call
lager:debug() and replace it with real calls. It is designed this way so as
to provide an unsurprising interface to the developer (logging at specific
severity levels), and so that it can filter out unconsumable log messages
at the callsite rather than filtering them out in the gen_event that
receives the log messages. Essentially, the code injection transforms the
function name ('debug' in this case) into the severity level, adds some
metadata to the message (line, module, pid, etc), and then does a few
checks to verify that the message is loggable. For instance, it will check
whether the log sink process is running, and that there exists at least one
output handler that is consuming that severity or lower, or that there is
an existing trace that matches. Only *then* will it log the message.

I would recommend using rebar3 or similar tools that can apply the
parse_transform across all of your code, instead of calling erlc directly.



On Thu, Jan 21, 2016 at 8:56 AM, Martin Koroudjiev <mrtndimitrov@REDACTED>
wrote:

> Hello,
>
> I am trying to include lager into our application but I am having
> problems. I include the lager ebin directory on startup with: -pa
> "../lib/lager-2.0.3/ebin"
> Then I start lager with: lager:start().
> I define a constant as: -define(dbg(Fmt), lager:debug(Fmt)).
> But when I try to use it in the code:
> ?dbg("Hello").
> it says: ** exception error: undefined function lager:debug/1
>
> I've checked lager's help page on github and saw that a parse_transform
> must be set to lager_transform. Why is this needed?
>
> And how to actually do it? I compile my source files with erlc and pass
> the transform option with +"{parse_transform, lager_transform}" but then
> the code doesn't compile because lager_transform module is not present
> at that time.
>
> Thank you,
> Martin
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160121/69b12e3a/attachment.htm>


More information about the erlang-questions mailing list