streetcornerlurker
streetcornerlurker

Reputation: 501

How does ~1024p get into my lager logs sometimes?

I'm using lager in an erlang app, and I occasionally have log statements like the following:

?log_error("failed to create reward instance: ~1024p", Reason)

where Reason was returned from a previous function call. As I understand it ~1024p should be turned into whatever Reason is, so that even if Reason is an empty string I would expect

failed to create reward instance: ""

but sometimes I get

failed to create reward instance: ~1024p

I'm just wondering if anyone can explain this behaviour. Thanks in advance.

Edit: The macro definition of ?log_error is:

-define(log_error(Message, Arguments), ?do_log_error(Message, Arguments) ).

-define(do_log_error(Message, Arguments), ?log(error, Message, Arguments)).

-define(log(Level, Message, Arguments), ok = lager:Level(Message, Arguments)).

This means that ?log_debug("...", Reason) calls lager:error("...",Reason) in the end. I don't see the function error in lager.erl. I'm guessing it must have to do with -compile([{parse_transform, lager_transform}]).. Unfortunately I don't know enough about parse transforms yet.

Thanks.

Upvotes: 1

Views: 60

Answers (1)

Steve Vinoski
Steve Vinoski

Reputation: 20024

The argument to your macro should always be a list, one for each formatting specifier in your format string, as that's what's required by the lager functions your macro calls:

?log_error("failed to create reward instance: ~1024p", [Reason])

Upvotes: 2

Related Questions