Bläddra i källkod

Added badfun support, and tests for progress reports

pull/4/head
Andrew Thompson 14 år sedan
förälder
incheckning
6916a66d0f
2 ändrade filer med 30 tillägg och 1 borttagningar
  1. +2
    -0
      src/error_logger_lager_h.erl
  2. +28
    -1
      test/lager_test_backend.erl

+ 2
- 0
src/error_logger_lager_h.erl Visa fil

@ -148,6 +148,8 @@ format_reason({{badarity, {Fun, Args}}, [MFA|_]}) ->
io_lib:format("fun called with wrong arity of ~w instead of ~w in ", [length(Args), Arity]) ++ format_mfa(MFA);
format_reason({noproc, MFA}) ->
"no such process or port in call to " ++ format_mfa(MFA);
format_reason({{badfun, Term}, [MFA|_]}) ->
io_lib:format("bad function ~w in ", [Term]) ++ format_mfa(MFA);
format_reason(Reason) ->
{Str, _} = trunc_io:print(Reason, 500),
Str.

+ 28
- 1
test/lager_test_backend.erl Visa fil

@ -316,7 +316,17 @@ error_logger_redirect_crash_test_() ->
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: no such process or port in call to gen_event:call(foo, bar, baz)", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"badfun",
fun() ->
Pid = whereis(crash),
crash(badfun),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: bad function booger in crash:handle_call/3", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
end
}
]
}.
@ -416,8 +426,25 @@ error_logger_redirect_test_() ->
Expected = lists:flatten(io_lib:format("[error] ~w Supervisor steve had child at module mini_steve at bleh exit with reason fired in context france", [self()])),
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"application progress report",
fun() ->
error_logger:info_report(progress, [{application, foo}, {started_at, node()}]),
timer:sleep(100),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[info] ~w Application foo started on node ~w", [self(), node()])),
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"supervisor progress report",
fun() ->
error_logger:info_report(progress, [{supervisor, {local, foo}}, {started, [{mfargs, {foo, bar, 1}}, {pid, baz}]}]),
timer:sleep(100),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[info] ~w Supervisor foo started foo:bar/1 at pid baz", [self()])),
?assertEqual(Expected, lists:flatten(Msg))
end
}
%% TODO progress reports
]
}.

Laddar…
Avbryt
Spara