Browse Source

Plug some large error_logger message holes with trunc_io

pull/4/merge
Andrew Thompson 14 years ago
parent
commit
0d3e45a39e
2 changed files with 54 additions and 8 deletions
  1. +11
    -7
      src/error_logger_lager_h.erl
  2. +43
    -1
      test/lager_test_backend.erl

+ 11
- 7
src/error_logger_lager_h.erl View File

@ -80,7 +80,7 @@ handle_event(Event, State) ->
[ID, Name, format_reason(Reason)]); [ID, Name, format_reason(Reason)]);
_ -> _ ->
?CRASH_LOG(Event), ?CRASH_LOG(Event),
?LOG(error, Pid, Fmt, Args)
?LOG(error, Pid, lager_trunc_io:format(Fmt, Args, 4096))
end; end;
{error_report, _GL, {Pid, std_error, D}} -> {error_report, _GL, {Pid, std_error, D}} ->
?CRASH_LOG(Event), ?CRASH_LOG(Event),
@ -98,11 +98,11 @@ handle_event(Event, State) ->
?CRASH_LOG(Event), ?CRASH_LOG(Event),
?LOG(error, Pid, ["CRASH REPORT ", format_crash_report(Self, Neighbours)]); ?LOG(error, Pid, ["CRASH REPORT ", format_crash_report(Self, Neighbours)]);
{warning_msg, _GL, {Pid, Fmt, Args}} -> {warning_msg, _GL, {Pid, Fmt, Args}} ->
?LOG(warning, Pid, Fmt, Args);
?LOG(warning, Pid, lager_trunc_io:format(Fmt, Args, 4096));
{warning_report, _GL, {Pid, std_warning, Report}} -> {warning_report, _GL, {Pid, std_warning, Report}} ->
?LOG(warning, Pid, print_silly_list(Report)); ?LOG(warning, Pid, print_silly_list(Report));
{info_msg, _GL, {Pid, Fmt, Args}} -> {info_msg, _GL, {Pid, Fmt, Args}} ->
?LOG(info, Pid, Fmt, Args);
?LOG(info, Pid, lager_trunc_io:format(Fmt, Args, 4096));
{info_report, _GL, {Pid, std_info, D}} when is_list(D) -> {info_report, _GL, {Pid, std_info, D}} when is_list(D) ->
Details = lists:sort(D), Details = lists:sort(D),
case Details of case Details of
@ -235,14 +235,18 @@ format_args([_|T], Acc) ->
print_silly_list(L) when is_list(L) -> print_silly_list(L) when is_list(L) ->
case lager_stdlib:string_p(L) of case lager_stdlib:string_p(L) of
true -> L;
_ -> print_silly_list(L, [], [])
true ->
lager_trunc_io:format("~s", [L], 4096);
_ ->
print_silly_list(L, [], [])
end; end;
print_silly_list(L) -> print_silly_list(L) ->
io_lib:format("~w", [L]).
{Str, _} = lager_trunc_io:print(L, 4096),
Str.
print_silly_list([], Fmt, Acc) -> print_silly_list([], Fmt, Acc) ->
io_lib:format(string:join(lists:reverse(Fmt), ", "), lists:reverse(Acc));
lager_trunc_io:format(string:join(lists:reverse(Fmt), ", "),
lists:reverse(Acc), 4096);
print_silly_list([{K,V}|T], Fmt, Acc) -> print_silly_list([{K,V}|T], Fmt, Acc) ->
print_silly_list(T, ["~w: ~w" | Fmt], [V, K | Acc]); print_silly_list(T, ["~w: ~w" | Fmt], [V, K | Acc]);
print_silly_list([H|T], Fmt, Acc) -> print_silly_list([H|T], Fmt, Acc) ->

+ 43
- 1
test/lager_test_backend.erl View File

@ -386,6 +386,14 @@ error_logger_redirect_test_() ->
?assertEqual(Expected, lists:flatten(Msg)) ?assertEqual(Expected, lists:flatten(Msg))
end end
}, },
{"error messages are truncated at 4096 characters",
fun() ->
error_logger:error_msg("doom, doom has come upon you all ~p", [string:copies("doom", 10000)]),
timer:sleep(100),
{_, _, Msg} = pop(),
?assert(length(lists:flatten(Msg)) < 5100)
end
},
{"info reports are printed", {"info reports are printed",
fun() -> fun() ->
error_logger:info_report([{this, is}, a, {silly, format}]), error_logger:info_report([{this, is}, a, {silly, format}]),
@ -395,6 +403,14 @@ error_logger_redirect_test_() ->
?assertEqual(Expected, lists:flatten(Msg)) ?assertEqual(Expected, lists:flatten(Msg))
end end
}, },
{"info reports are truncated at 4096 characters",
fun() ->
error_logger:info_report([[{this, is}, a, {silly, format}] || _ <- lists:seq(0, 600)]),
timer:sleep(1000),
{_, _, Msg} = pop(),
?assert(length(lists:flatten(Msg)) < 5000)
end
},
{"single term info reports are printed", {"single term info reports are printed",
fun() -> fun() ->
error_logger:info_report({foolish, bees}), error_logger:info_report({foolish, bees}),
@ -422,6 +438,15 @@ error_logger_redirect_test_() ->
?assertEqual(Expected, lists:flatten(Msg)) ?assertEqual(Expected, lists:flatten(Msg))
end end
}, },
{"string info reports are truncated at 4096 characters",
fun() ->
error_logger:info_report(string:copies("this is less silly", 1000)),
timer:sleep(100),
{_, _, Msg} = pop(),
?assert(length(lists:flatten(Msg)) < 5100)
end
},
{"info messages are printed", {"info messages are printed",
fun() -> fun() ->
error_logger:info_msg("doom, doom has come upon you all"), error_logger:info_msg("doom, doom has come upon you all"),
@ -431,6 +456,15 @@ error_logger_redirect_test_() ->
?assertEqual(Expected, lists:flatten(Msg)) ?assertEqual(Expected, lists:flatten(Msg))
end end
}, },
{"info messages are truncated at 4096 characters",
fun() ->
error_logger:info_msg("doom, doom has come upon you all ~p", [string:copies("doom", 10000)]),
timer:sleep(100),
{_, _, Msg} = pop(),
?assert(length(lists:flatten(Msg)) < 5100)
end
},
{"warning messages are printed at the correct level", {"warning messages are printed at the correct level",
fun() -> fun() ->
error_logger:warning_msg("doom, doom has come upon you all"), error_logger:warning_msg("doom, doom has come upon you all"),
@ -571,7 +605,15 @@ error_logger_redirect_test_() ->
?assertEqual(Expected, lists:flatten(Msg)) ?assertEqual(Expected, lists:flatten(Msg))
end end
}, },
{"crash report for unknown system limit should be truncated at 500 characters",
fun() ->
error_logger:error_report(crash_report, [[{pid, self()}, {error_info, {error, {system_limit,[{wtf,boom,[string:copies("aaaa", 4096)]}]}, []}}], []]),
timer:sleep(100),
{_, _, Msg} = pop(),
?assert(length(lists:flatten(Msg)) > 500),
?assert(length(lists:flatten(Msg)) < 700)
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),

Loading…
Cancel
Save