From bb8a07ca8295a506e06fbf0b2173e6cd55b3d523 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Wed, 14 Jun 2017 13:16:39 +0200 Subject: sasl: Improve handling of Unicode There is more to do. --- lib/sasl/src/sasl_report.erl | 81 ++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 30 deletions(-) (limited to 'lib/sasl/src') diff --git a/lib/sasl/src/sasl_report.erl b/lib/sasl/src/sasl_report.erl index eb454155d5..e6556ec6ce 100644 --- a/lib/sasl/src/sasl_report.erl +++ b/lib/sasl/src/sasl_report.erl @@ -47,6 +47,7 @@ io_report(_IO, _Fd, _, _) -> is_my_error_report(all, Type) -> is_my_error_report(Type); is_my_error_report(error, Type) -> is_my_error_report(Type); is_my_error_report(_, _Type) -> false. + is_my_error_report(supervisor_report) -> true; is_my_error_report(crash_report) -> true; is_my_error_report(_) -> false. @@ -54,6 +55,7 @@ is_my_error_report(_) -> false. is_my_info_report(all, Type) -> is_my_info_report(Type); is_my_info_report(progress, Type) -> is_my_info_report(Type); is_my_info_report(_, _Type) -> false. + is_my_info_report(progress) -> true; is_my_info_report(_) -> false. @@ -62,46 +64,65 @@ write_report2(IO, Fd, Head, supervisor_report, Report) -> Context = sup_get(errorContext, Report), Reason = sup_get(reason, Report), Offender = sup_get(offender, Report), - {FmtString,Args} = supervisor_format([Name,Context,Reason,Offender]), - write_report_action(IO, Fd, Head, FmtString, Args); + Enc = encoding(Fd), + {FmtString,Args} = supervisor_format([Name,Context,Reason,Offender], Enc), + String = io_lib:format(FmtString, Args), + write_report_action(IO, Fd, Head, String); write_report2(IO, Fd, Head, progress, Report) -> - Format = format_key_val(Report), - write_report_action(IO, Fd, Head, "~s", [Format]); + Encoding = encoding(Fd), + Depth = error_logger:get_format_depth(), + String = format_key_val(Report, Encoding, Depth), + write_report_action(IO, Fd, Head, String); write_report2(IO, Fd, Head, crash_report, Report) -> + Encoding = encoding(Fd), Depth = error_logger:get_format_depth(), - Format = proc_lib:format(Report, latin1, Depth), - write_report_action(IO, Fd, Head, "~s", [Format]). - -supervisor_format(Args0) -> - case error_logger:get_format_depth() of - unlimited -> - {" Supervisor: ~p~n" - " Context: ~p~n" - " Reason: ~80.18p~n" - " Offender: ~80.18p~n~n", - Args0}; - Depth -> - [A,B,C,D] = Args0, - Args = [A,Depth,B,Depth,C,Depth,D,Depth], - {" Supervisor: ~P~n" - " Context: ~P~n" - " Reason: ~80.18P~n" - " Offender: ~80.18P~n~n", - Args} - end. - -write_report_action(IO, Fd, Head, Format, Args) -> - S = [Head|io_lib:format(Format, Args)], + String = proc_lib:format(Report, Encoding, Depth), + write_report_action(IO, Fd, Head, String). + +supervisor_format(Args0, Encoding) -> + {P, Tl} = p(Encoding, error_logger:get_format_depth()), + [A,B,C,D] = Args0, + Args = [A|Tl] ++ [B|Tl] ++ [C|Tl] ++ [D|Tl], + {" Supervisor: ~" ++ P ++ "\n" + " Context: ~" ++ P ++ "\n" + " Reason: ~80.18" ++ P ++ "\n" + " Offender: ~80.18" ++ P ++ "\n~n", + Args}. + +write_report_action(IO, Fd, Head, String) -> + S = [Head|String], case IO of io -> io:put_chars(Fd, S); io_lib -> S end. -format_key_val([{Tag,Data}|Rep]) -> - io_lib:format(" ~16w: ~p~n",[Tag,Data]) ++ format_key_val(Rep); -format_key_val(_) -> +format_key_val(Rep, Encoding, Depth) -> + {P, Tl} = p(Encoding, Depth), + format_key_val1(Rep, P, Tl). + +format_key_val1([{Tag,Data}|Rep], P, Tl) -> + (io_lib:format(" ~16w: ~" ++ P ++ "\n", [Tag, Data|Tl]) ++ + format_key_val1(Rep, P, Tl)); +format_key_val1(_, _, _) -> []. +p(Encoding, Depth) -> + {Letter, Tl} = case Depth of + unlimited -> {"p", []}; + _ -> {"P", [Depth]} + end, + P = modifier(Encoding) ++ Letter, + {P, Tl}. + +encoding(IO) -> + case lists:keyfind(encoding, 1, io:getopts(IO)) of + false -> latin1; + {encoding, Enc} -> Enc + end. + +modifier(latin1) -> ""; +modifier(_) -> "t". + sup_get(Tag, Report) -> case lists:keysearch(Tag, 1, Report) of {value, {_, Value}} -> -- cgit v1.2.3 From 2d553a01258416bc977b5afd06f83f22c3ac9ab4 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Tue, 22 Aug 2017 15:26:02 +0200 Subject: sasl: set encoding of SASL report log This can now be explicitly set by the 'sasl_error_logger' configuration parameter, but if not set, the default encoding is now utf8. When printing to this log, the Unicode translation modifier, t, might be used in the format string. --- lib/sasl/src/sasl_report_file_h.erl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'lib/sasl/src') diff --git a/lib/sasl/src/sasl_report_file_h.erl b/lib/sasl/src/sasl_report_file_h.erl index 21746839fa..d3b5c7dc0d 100644 --- a/lib/sasl/src/sasl_report_file_h.erl +++ b/lib/sasl/src/sasl_report_file_h.erl @@ -29,15 +29,27 @@ handle_event/2, handle_call/2, handle_info/2, terminate/2]). -init({File, Modes, Type}) when is_list(Modes) -> +init({File, Modes0, Type}) when is_list(Modes0) -> process_flag(trap_exit, true), + Modes1 = + case lists:keymember(encoding,1,Modes0) of + true -> Modes0; + false -> [{encoding,utf8}|Modes0] + end, + Modes = + case [M || M <- Modes1, lists:member(M,[write,append,exclusive])] of + [] -> + [write|Modes1]; + _ -> + Modes1 + end, case file:open(File, Modes) of {ok,Fd} -> {ok, {Fd, File, Type}}; What -> What end. - + handle_event({_Type, GL, _Msg}, State) when node(GL) /= node() -> {ok, State}; handle_event(Event, {Fd, File, Type}) -> -- cgit v1.2.3