Browse Source

Merge pull request #81 from ypaq/master

Added node to metadata in parse transfrom
pull/96/head
Andrew Thompson 12 years ago
parent
commit
bf1efd0573
3 changed files with 29 additions and 2 deletions
  1. +1
    -1
      README.org
  2. +24
    -0
      src/lager_console_backend.erl
  3. +4
    -1
      src/lager_transform.erl

+ 1
- 1
README.org View File

@ -95,7 +95,7 @@
as configuration. Any iolist allowed elements in the configuration are printed verbatim. Atoms in the configuration as configuration. Any iolist allowed elements in the configuration are printed verbatim. Atoms in the configuration
are treated as metadata properties and extracted from the log message. are treated as metadata properties and extracted from the log message.
The metadata properties date,time, message, and severity will always exist. The metadata properties date,time, message, and severity will always exist.
The properties pid, file, line, module, and function will always exist if the parser transform is used.
The properties pid, file, line, module, function, and node will always exist if the parser transform is used.
#+BEGIN_EXAMPLE #+BEGIN_EXAMPLE
["Foo"] -> "Foo", regardless of message content. ["Foo"] -> "Foo", regardless of message content.

+ 24
- 0
src/lager_console_backend.erl View File

@ -167,6 +167,30 @@ console_log_test_() ->
end end
end end
}, },
{"custom format console logging",
fun() ->
Pid = spawn(F(self())),
unregister(user),
register(user, Pid),
erlang:group_leader(Pid, whereis(lager_event)),
gen_event:add_handler(lager_event, lager_console_backend,
[info, {lager_default_formatter, [date,"#",time,"#",severity,"#",node,"#",pid,"#",
module,"#",function,"#",file,"#",line,"#",message,"\r\n"]}]),
lager_mochiglobal:put(loglevel, {?INFO, []}),
lager:info("Test message"),
PidStr = pid_to_list(self()),
NodeStr = atom_to_list(node()),
ModuleStr = atom_to_list(?MODULE),
receive
{io_request, _, _, {put_chars, unicode, Msg}} ->
?assertMatch([_, _, "info", NodeStr, PidStr, ModuleStr, _, _, _, "Test message\r\n"],
re:split(Msg, "#", [{return, list}, {parts, 10}]))
after
500 ->
?assert(false)
end
end
},
{"tracing should work", {"tracing should work",
fun() -> fun() ->
Pid = spawn(F(self())), Pid = spawn(F(self())),

+ 4
- 1
src/lager_transform.erl View File

@ -74,7 +74,10 @@ transform_statement({call, Line, {remote, _Line1, {atom, _Line2, lager},
{atom, Line, pid}, {atom, Line, pid},
{call, Line, {atom, Line, pid_to_list}, [ {call, Line, {atom, Line, pid_to_list}, [
{call, Line, {atom, Line ,self}, []}]}]}, {call, Line, {atom, Line ,self}, []}]}]},
{nil, Line}}}}},
{cons, Line, {tuple, Line, [
{atom, Line, node},
{call, Line, {atom, Line, node}, []}]},
{nil, Line}}}}}},
{Traces, Message, Arguments} = case Arguments0 of {Traces, Message, Arguments} = case Arguments0 of
[Format] -> [Format] ->
{DefaultAttrs, Format, {atom, Line, none}}; {DefaultAttrs, Format, {atom, Line, none}};

Loading…
Cancel
Save