Added node to metadata in parse transfrom #81

Merged
merged 2 commits into from Nov 28, 2012
View
2 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.
View
24 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())),
View
5 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}};