浏览代码

Merge mkurkov:fix/error-logger-backend-unicode, PR #259, with adjustments for handling extra data.

pull/277/head
Ted Burghart 10 年前
父节点
当前提交
b8a8ed0b28
共有 2 个文件被更改,包括 35 次插入3 次删除
  1. +3
    -3
      src/error_logger_lager_h.erl
  2. +32
    -0
      test/lager_test_backend.erl

+ 3
- 3
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)]); ?LOGFMT(error, Pid, "Webmachine error at path ~p : ~s", [Path, format_reason(StackTrace)]);
_ -> _ ->
?CRASH_LOG(Event), ?CRASH_LOG(Event),
?LOGMSG(error, Pid, lager:safe_format(Fmt, Args, ?DEFAULT_TRUNCATION))
?LOGFMT(error, Pid, Fmt, Args)
end; end;
{error_report, _GL, {Pid, std_error, D}} -> {error_report, _GL, {Pid, std_error, D}} ->
?CRASH_LOG(Event), ?CRASH_LOG(Event),
@ -217,11 +217,11 @@ log_event(Event, State) ->
?CRASH_LOG(Event), ?CRASH_LOG(Event),
?LOGMSG(error, Pid, "CRASH REPORT " ++ format_crash_report(Self, Neighbours)); ?LOGMSG(error, Pid, "CRASH REPORT " ++ format_crash_report(Self, Neighbours));
{warning_msg, _GL, {Pid, Fmt, Args}} -> {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}} -> {warning_report, _GL, {Pid, std_warning, Report}} ->
?LOGMSG(warning, Pid, print_silly_list(Report)); ?LOGMSG(warning, Pid, print_silly_list(Report));
{info_msg, _GL, {Pid, Fmt, Args}} -> {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) -> {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

+ 32
- 0
test/lager_test_backend.erl 查看文件

@ -753,6 +753,17 @@ error_logger_redirect_test_() ->
?assertEqual(Expected, lists:flatten(Msg)) ?assertEqual(Expected, lists:flatten(Msg))
end 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", {"error messages are truncated at 4096 characters",
fun() -> fun() ->
sync_error_logger:error_msg("doom, doom has come upon you all ~p", [string:copies("doom", 10000)]), sync_error_logger:error_msg("doom, doom has come upon you all ~p", [string:copies("doom", 10000)]),
@ -852,6 +863,27 @@ error_logger_redirect_test_() ->
?assert(length(lists:flatten(Msg)) < 5100) ?assert(length(lists:flatten(Msg)) < 5100)
end 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", {"warning messages are printed at the correct level",
fun() -> fun() ->

正在加载...
取消
保存