Browse Source

Handle 'single term' error_logger reports

pull/4/head
Andrew Thompson 14 years ago
parent
commit
e9abf79aac
2 changed files with 35 additions and 6 deletions
  1. +7
    -6
      src/error_logger_lager_h.erl
  2. +28
    -0
      test/lager_test_backend.erl

+ 7
- 6
src/error_logger_lager_h.erl View File

@ -81,12 +81,9 @@ handle_event(Event, State) ->
?LOG(warning, Pid, Fmt, Args);
{warning_report, _GL, {Pid, std_warning, Report}} ->
?LOG(warning, Pid, print_silly_list(Report));
{warning_report, _GL, {_Pid, _Type, _Report}} ->
%% ignore, non standard warning type
ok;
{info_msg, _GL, {Pid, Fmt, Args}} ->
?LOG(info, Pid, Fmt, Args);
{info_report, _GL, {Pid, std_info, D}} ->
{info_report, _GL, {Pid, std_info, D}} when is_list(D) ->
Details = lists:sort(D),
case Details of
[{application, App}, {exited, Reason}, {type, _Type}] ->
@ -94,6 +91,8 @@ handle_event(Event, State) ->
_ ->
?LOG(info, Pid, print_silly_list(D))
end;
{info_report, _GL, {Pid, std_info, D}} ->
?LOG(info, Pid, "~w", [D]);
{info_report, _GL, {P, progress, D}} ->
Details = lists:sort(D),
case Details of
@ -184,11 +183,13 @@ format_mfa({M, F, A}) when is_integer(A) ->
format_mfa(Other) ->
io_lib:format("~w", [Other]).
print_silly_list(L) ->
print_silly_list(L) when is_list(L) ->
case lager_stdlib:string_p(L) of
true -> L;
_ -> print_silly_list(L, [], [])
end.
end;
print_silly_list(L) ->
io_lib:format("~w", [L]).
print_silly_list([], Fmt, Acc) ->
io_lib:format(string:join(lists:reverse(Fmt), ", "), lists:reverse(Acc));

+ 28
- 0
test/lager_test_backend.erl View File

@ -382,6 +382,24 @@ error_logger_redirect_test_() ->
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"single term info reports are printed",
fun() ->
error_logger:info_report({foolish, bees}),
timer:sleep(100),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[info] ~w {foolish,bees}", [self()])),
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"single term error reports are printed",
fun() ->
error_logger:error_report({foolish, bees}),
timer:sleep(100),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w {foolish,bees}", [self()])),
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"string info reports are printed",
fun() ->
error_logger:info_report("this is less silly"),
@ -420,6 +438,16 @@ error_logger_redirect_test_() ->
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"single term warning reports are printed at the correct level",
fun() ->
error_logger:warning_report({foolish, bees}),
Map = error_logger:warning_map(),
timer:sleep(100),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[~w] ~w {foolish,bees}", [Map, self()])),
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"application stop reports",
fun() ->
error_logger:info_report([{application, foo}, {exited, quittin_time}, {type, lazy}]),

Loading…
Cancel
Save