From e9fba0d64c99a10bd0c68af8b22546aa0d6a9934 Mon Sep 17 00:00:00 2001 From: Mikl Kurkov Date: Wed, 22 Apr 2015 15:26:12 +0300 Subject: [PATCH 1/2] Fix noproc test fail --- test/lager_test_backend.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lager_test_backend.erl b/test/lager_test_backend.erl index 71b9de9..bc06788 100644 --- a/test/lager_test_backend.erl +++ b/test/lager_test_backend.erl @@ -651,7 +651,7 @@ error_logger_redirect_crash_test_() -> TestBody("bad arg1",badarg1,"gen_server crash terminated with reason: bad argument in crash:handle_call/3"), TestBody("bad arg2",badarg2,"gen_server crash terminated with reason: bad argument in call to erlang:iolist_to_binary([\"foo\",bar]) in crash:handle_call/3"), TestBody("bad record",badrecord,"gen_server crash terminated with reason: bad record state in crash:handle_call/3"), - TestBody("noproc",noproc,"gen_server crash terminated with reason: no such process or port in call to gen_event:call(foo, bar, baz)"), + TestBody("noproc",noproc,"gen_server crash terminated with reason: no such process or port in call to gen_event:call(foo, bar, baz) in gen_event:call1/3"), TestBody("badfun",badfun,"gen_server crash terminated with reason: bad function booger in crash:handle_call/3") ] }. From 171e9596eacec79a33ae40749ff2072c48a1b6c7 Mon Sep 17 00:00:00 2001 From: Mikl Kurkov Date: Wed, 22 Apr 2015 15:49:38 +0300 Subject: [PATCH 2/2] Fix error_logger backend 'Format error' on unicode in Args --- src/error_logger_lager_h.erl | 6 +++--- test/lager_test_backend.erl | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/error_logger_lager_h.erl b/src/error_logger_lager_h.erl index ec0bfb2..6ce2bcc 100644 --- a/src/error_logger_lager_h.erl +++ b/src/error_logger_lager_h.erl @@ -197,7 +197,7 @@ log_event(Event, State) -> ?LOGFMT(error, Pid, "Webmachine error at path ~p : ~s", [Path, format_reason(StackTrace)]); _ -> ?CRASH_LOG(Event), - ?LOGMSG(error, Pid, lager:safe_format(Fmt, Args, ?DEFAULT_TRUNCATION)) + ?LOGFMT(error, Pid, Fmt, Args) end; {error_report, _GL, {Pid, std_error, D}} -> ?CRASH_LOG(Event), @@ -217,11 +217,11 @@ log_event(Event, State) -> ?CRASH_LOG(Event), ?LOGMSG(error, Pid, "CRASH REPORT " ++ format_crash_report(Self, Neighbours)); {warning_msg, _GL, {Pid, Fmt, Args}} -> - ?LOGMSG(warning, Pid, lager:safe_format(Fmt, Args, ?DEFAULT_TRUNCATION)); + ?LOGFMT(warning, Pid, Fmt, Args); {warning_report, _GL, {Pid, std_warning, Report}} -> ?LOGMSG(warning, Pid, print_silly_list(Report)); {info_msg, _GL, {Pid, Fmt, Args}} -> - ?LOGMSG(info, Pid, lager:safe_format(Fmt, Args, ?DEFAULT_TRUNCATION)); + ?LOGFMT(info, Pid, Fmt, Args); {info_report, _GL, {Pid, std_info, D}} when is_list(D) -> Details = lists:sort(D), case Details of diff --git a/test/lager_test_backend.erl b/test/lager_test_backend.erl index bc06788..5904593 100644 --- a/test/lager_test_backend.erl +++ b/test/lager_test_backend.erl @@ -709,6 +709,17 @@ error_logger_redirect_test_() -> ?assertEqual(Expected, lists:flatten(Msg)) end }, + {"error messages with unicode characters in Args are printed", + fun() -> + sync_error_logger:error_msg("~ts", ["Привет!"]), + _ = 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("Привет!", lists:flatten(Msg)) + end + }, + {"error messages are truncated at 4096 characters", fun() -> sync_error_logger:error_msg("doom, doom has come upon you all ~p", [string:copies("doom", 10000)]), @@ -808,6 +819,27 @@ error_logger_redirect_test_() -> ?assert(length(lists:flatten(Msg)) < 5100) end }, + {"info messages with unicode characters in Args are printed", + fun() -> + sync_error_logger:info_msg("~ts", ["Привет!"]), + _ = gen_event:which_handlers(error_logger), + {Level, _, Msg,Metadata} = pop(), + ?assertEqual(lager_util:level_to_num(info),Level), + ?assertEqual(self(),proplists:get_value(pid,Metadata)), + ?assertEqual("Привет!", lists:flatten(Msg)) + end + }, + {"warning messages with unicode characters in Args are printed", + fun() -> + sync_error_logger:warning_msg("~ts", ["Привет!"]), + Map = error_logger:warning_map(), + _ = gen_event:which_handlers(error_logger), + {Level, _, Msg,Metadata} = pop(), + ?assertEqual(lager_util:level_to_num(Map),Level), + ?assertEqual(self(),proplists:get_value(pid,Metadata)), + ?assertEqual("Привет!", lists:flatten(Msg)) + end + }, {"warning messages are printed at the correct level", fun() ->