Преглед изворни кода

Merge pull request #81 from ypaq/master

Added node to metadata in parse transfrom
pull/96/head
Andrew Thompson пре 12 година
родитељ
комит
bf1efd0573
3 измењених фајлова са 29 додато и 2 уклоњено
  1. +1
    -1
      README.org
  2. +24
    -0
      src/lager_console_backend.erl
  3. +4
    -1
      src/lager_transform.erl

+ 1
- 1
README.org Прегледај датотеку

@ -95,7 +95,7 @@
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.
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
["Foo"] -> "Foo", regardless of message content.

+ 24
- 0
src/lager_console_backend.erl Прегледај датотеку

@ -167,6 +167,30 @@ console_log_test_() ->
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",
fun() ->
Pid = spawn(F(self())),

+ 4
- 1
src/lager_transform.erl Прегледај датотеку

@ -74,7 +74,10 @@ transform_statement({call, Line, {remote, _Line1, {atom, _Line2, lager},
{atom, Line, pid},
{call, Line, {atom, Line, pid_to_list}, [
{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
[Format] ->
{DefaultAttrs, Format, {atom, Line, none}};

Loading…
Откажи
Сачувај