Parcourir la source

Merge pull request #32 from basho/adt-better-crash-reports

Better crash reports for processes started via proc_lib, Fixes #31
pull/35/merge
Andrew Thompson il y a 13 ans
Parent
révision
c9173d73e1
3 fichiers modifiés avec 49 ajouts et 2 suppressions
  1. +8
    -2
      src/error_logger_lager_h.erl
  2. +13
    -0
      test/lager_test_backend.erl
  3. +28
    -0
      test/special_process.erl

+ 8
- 2
src/error_logger_lager_h.erl Voir le fichier

@ -159,9 +159,15 @@ format_crash_report(Report, Neighbours) ->
proplists:get_value(pid, Report); proplists:get_value(pid, Report);
Atom -> Atom Atom -> Atom
end, end,
{_Class, Reason, _Trace} = proplists:get_value(error_info, Report),
{_Class, Reason, Trace} = proplists:get_value(error_info, Report),
ReasonStr = case is_atom(Reason) of
true ->
format_reason({Reason, Trace});
_ ->
format_reason(Reason)
end,
io_lib:format("Process ~w with ~w neighbours crashed with reason: ~s", io_lib:format("Process ~w with ~w neighbours crashed with reason: ~s",
[Name, length(Neighbours), format_reason(Reason)]).
[Name, length(Neighbours), ReasonStr]).
format_offender(Off) -> format_offender(Off) ->
case proplists:get_value(mfargs, Off) of case proplists:get_value(mfargs, Off) of

+ 13
- 0
test/lager_test_backend.erl Voir le fichier

@ -685,6 +685,19 @@ error_logger_redirect_test_() ->
?assert(length(lists:flatten(Msg)) < 650) ?assert(length(lists:flatten(Msg)) < 650)
end end
}, },
{"crash reports for 'special processes' should be handled right",
fun() ->
{ok, Pid} = special_process:start(),
unlink(Pid),
Pid ! function_clause,
timer:sleep(500),
_ = gen_event:which_handlers(error_logger),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~p CRASH REPORT Process ~p with 0 neighbours crashed with reason: no function clause matching special_process:foo(bar)",
[Pid, Pid])),
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"messages should not be generated if they don't satisfy the threshold", {"messages should not be generated if they don't satisfy the threshold",
fun() -> fun() ->
lager:set_loglevel(?MODULE, error), lager:set_loglevel(?MODULE, error),

+ 28
- 0
test/special_process.erl Voir le fichier

@ -0,0 +1,28 @@
-module(special_process).
-export([start/0, init/1]).
start() ->
proc_lib:start_link(?MODULE, init, [self()]).
init(Parent) ->
proc_lib:init_ack(Parent, {ok, self()}),
loop().
loop() ->
receive
function_clause ->
foo(bar),
loop();
exit ->
exit(byebye),
loop();
error ->
erlang:error(mybad),
loop();
_ ->
loop()
end.
foo(baz) ->
ok.

Chargement…
Annuler
Enregistrer