diff --git a/src/error_logger_lager_h.erl b/src/error_logger_lager_h.erl index 907d831..b359ee5 100644 --- a/src/error_logger_lager_h.erl +++ b/src/error_logger_lager_h.erl @@ -80,7 +80,7 @@ handle_event(Event, State) -> [ID, Name, format_reason(Reason)]); _ -> ?CRASH_LOG(Event), - ?LOG(error, Pid, Fmt, Args) + ?LOG(error, Pid, lager_trunc_io:format(Fmt, Args, 4096)) end; {error_report, _GL, {Pid, std_error, D}} -> ?CRASH_LOG(Event), @@ -98,11 +98,11 @@ handle_event(Event, State) -> ?CRASH_LOG(Event), ?LOG(error, Pid, ["CRASH REPORT ", format_crash_report(Self, Neighbours)]); {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}} -> ?LOG(warning, Pid, print_silly_list(Report)); {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) -> Details = lists:sort(D), case Details of @@ -235,14 +235,18 @@ format_args([_|T], Acc) -> print_silly_list(L) when is_list(L) -> 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; print_silly_list(L) -> - io_lib:format("~w", [L]). + {Str, _} = lager_trunc_io:print(L, 4096), + Str. 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(T, ["~w: ~w" | Fmt], [V, K | Acc]); print_silly_list([H|T], Fmt, Acc) -> diff --git a/test/lager_test_backend.erl b/test/lager_test_backend.erl index 0d542fd..f5bed9d 100644 --- a/test/lager_test_backend.erl +++ b/test/lager_test_backend.erl @@ -386,6 +386,14 @@ error_logger_redirect_test_() -> ?assertEqual(Expected, lists:flatten(Msg)) 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", fun() -> error_logger:info_report([{this, is}, a, {silly, format}]), @@ -395,6 +403,14 @@ error_logger_redirect_test_() -> ?assertEqual(Expected, lists:flatten(Msg)) 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", fun() -> error_logger:info_report({foolish, bees}), @@ -422,6 +438,15 @@ error_logger_redirect_test_() -> ?assertEqual(Expected, lists:flatten(Msg)) 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", fun() -> error_logger:info_msg("doom, doom has come upon you all"), @@ -431,6 +456,15 @@ error_logger_redirect_test_() -> ?assertEqual(Expected, lists:flatten(Msg)) 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", fun() -> error_logger:warning_msg("doom, doom has come upon you all"), @@ -571,7 +605,15 @@ error_logger_redirect_test_() -> ?assertEqual(Expected, lists:flatten(Msg)) 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", fun() -> lager:set_loglevel(?MODULE, error),