Selaa lähdekoodia

Support warning messages, put commas between terms in report messages

pull/4/head
Andrew Thompson 14 vuotta sitten
vanhempi
commit
5b9a4c6161
2 muutettua tiedostoa jossa 31 lisäystä ja 5 poistoa
  1. +8
    -2
      src/error_logger_lager_h.erl
  2. +23
    -3
      test/lager_test_backend.erl

+ 8
- 2
src/error_logger_lager_h.erl Näytä tiedosto

@ -37,7 +37,6 @@
_ -> ok
end).
init(_) ->
{ok, {}}.
@ -78,6 +77,13 @@ handle_event(Event, State) ->
end;
{error_report, _GL, {Pid, crash_report, [Self, Neighbours]}} ->
?LOG(error, Pid, ["CRASH REPORT ", format_crash_report(Self, Neighbours)]);
{warning_msg, _GL, {Pid, Fmt, Args}} ->
?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}} ->
@ -185,7 +191,7 @@ print_silly_list(L) ->
end.
print_silly_list([], Fmt, Acc) ->
io_lib:format(string:join(lists:reverse(Fmt), " "), lists:reverse(Acc));
io_lib:format(string:join(lists:reverse(Fmt), ", "), lists:reverse(Acc));
print_silly_list([{K,V}|T], Fmt, Acc) ->
print_silly_list(T, ["~w: ~w" | Fmt], [V, K | Acc]);
print_silly_list([H|T], Fmt, Acc) ->

+ 23
- 3
test/lager_test_backend.erl Näytä tiedosto

@ -351,7 +351,7 @@ error_logger_redirect_test_() ->
error_logger:error_report([{this, is}, a, {silly, format}]),
timer:sleep(100),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w this: is a silly: format", [self()])),
Expected = lists:flatten(io_lib:format("[error] ~w this: is, a, silly: format", [self()])),
?assertEqual(Expected, lists:flatten(Msg))
end
},
@ -378,7 +378,7 @@ error_logger_redirect_test_() ->
error_logger:info_report([{this, is}, a, {silly, format}]),
timer:sleep(100),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[info] ~w this: is a silly: format", [self()])),
Expected = lists:flatten(io_lib:format("[info] ~w this: is, a, silly: format", [self()])),
?assertEqual(Expected, lists:flatten(Msg))
end
},
@ -391,7 +391,7 @@ error_logger_redirect_test_() ->
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"error messages are printed",
{"info messages are printed",
fun() ->
error_logger:info_msg("doom, doom has come upon you all"),
timer:sleep(100),
@ -400,6 +400,26 @@ error_logger_redirect_test_() ->
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"warning messages are printed at the correct level",
fun() ->
error_logger:warning_msg("doom, doom has come upon you all"),
Map = error_logger:warning_map(),
timer:sleep(100),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[~w] ~w doom, doom has come upon you all", [Map, self()])),
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"warning reports are printed at the correct level",
fun() ->
error_logger:warning_report([{i, like}, pie]),
Map = error_logger:warning_map(),
timer:sleep(100),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[~w] ~w i: like, pie", [Map, self()])),
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"application stop reports",
fun() ->
error_logger:info_report([{application, foo}, {exited, quittin_time}, {type, lazy}]),

Ladataan…
Peruuta
Tallenna