Permalink
Browse files

Replaced another use of element(2,Pid). Added some tests with somepid…

… instead {local,name} as supervisor reference
  • Loading branch information...
1 parent 31a1e9e commit e133ca4992caf5bd68df85521e87fa5ec1637701 @mworrell committed Mar 7, 2013
Showing with 28 additions and 6 deletions.
  1. +6 −6 src/error_logger_lager_h.erl
  2. +22 −0 test/lager_test_backend.erl
View
12 src/error_logger_lager_h.erl
@@ -98,13 +98,9 @@ handle_event(Event, State) ->
case lists:sort(D) of
[{errorContext, Ctx}, {offender, Off}, {reason, Reason}, {supervisor, Name}] ->
Offender = format_offender(Off),
- Name1 = case Name of
- {local, N} -> N;
- _ -> Name
- end,
?LOGFMT(error, Pid,
"Supervisor ~w had child ~s exit with reason ~s in context ~w",
- [Name1, Offender, format_reason(Reason), Ctx]);
+ [supervisor_name(Name), Offender, format_reason(Reason), Ctx]);
_ ->
?LOGMSG(error, Pid, "SUPERVISOR REPORT " ++ print_silly_list(D))
end;
@@ -138,7 +134,7 @@ handle_event(Event, State) ->
MFA = format_mfa(proplists:get_value(mfargs, Started)),
Pid = proplists:get_value(pid, Started),
?LOGFMT(debug, P, "Supervisor ~w started ~s at pid ~w",
- [element(2, Name), MFA, Pid]);
+ [supervisor_name(Name), MFA, Pid]);
_ ->
?LOGMSG(info, P, "PROGRESS REPORT " ++ print_silly_list(D))
end;
@@ -315,3 +311,7 @@ print_silly_list([H|T], Fmt, Acc) ->
print_val(Val) ->
{Str, _} = lager_trunc_io:print(Val, 500),
Str.
+
+
+supervisor_name({local, Name}) -> Name;
+supervisor_name(Name) -> Name.
View
22 test/lager_test_backend.erl
@@ -730,6 +730,17 @@ error_logger_redirect_test_() ->
end
},
+ {"supervisor reports with real error and pid",
+ fun() ->
+ sync_error_logger:error_report(supervisor_report, [{errorContext, france}, {offender, [{name, mini_steve}, {mfargs, {a, b, [c]}}, {pid, bleh}]}, {reason, {function_clause,[{crash,handle_info,[foo]}]}}, {supervisor, somepid}]),
+ _ = gen_event:which_handlers(error_logger),
+ {Level, _, Msg,Metadata} = pop(),
+ ?assertEqual(lager_util:level_to_num(error),Level),
+ ?assertEqual(self(),proplists:get_value(pid,Metadata)),
+ ?assertEqual("Supervisor somepid had child mini_steve started with a:b(c) at bleh exit with reason no function clause matching crash:handle_info(foo) in context france", lists:flatten(Msg))
+ end
+ },
+
{"supervisor_bridge reports",
fun() ->
sync_error_logger:error_report(supervisor_report, [{errorContext, france}, {offender, [{mod, mini_steve}, {pid, bleh}]}, {reason, fired}, {supervisor, {local, steve}}]),
@@ -762,6 +773,17 @@ error_logger_redirect_test_() ->
?assertEqual("Supervisor foo started foo:bar/1 at pid baz", lists:flatten(Msg))
end
},
+ {"supervisor progress report with pid",
+ fun() ->
+ lager:set_loglevel(?MODULE, debug),
+ sync_error_logger:info_report(progress, [{supervisor, somepid}, {started, [{mfargs, {foo, bar, 1}}, {pid, baz}]}]),
+ _ = gen_event:which_handlers(error_logger),
+ {Level, _, Msg,Metadata} = pop(),
+ ?assertEqual(lager_util:level_to_num(debug),Level),
+ ?assertEqual(self(),proplists:get_value(pid,Metadata)),
+ ?assertEqual("Supervisor somepid started foo:bar/1 at pid baz", lists:flatten(Msg))
+ end
+ },
{"crash report for emfile",
fun() ->
sync_error_logger:error_report(crash_report, [[{pid, self()}, {registered_name, []}, {error_info, {error, emfile, [{stack, trace, 1}]}}], []]),

0 comments on commit e133ca4

Please sign in to comment.