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/doc/src/sasl_app.xml | 9 ++++++--- lib/sasl/src/sasl_report_file_h.erl | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/sasl/doc/src/sasl_app.xml b/lib/sasl/doc/src/sasl_app.xml index 0576397f9b..e0693fcb60 100644 --- a/lib/sasl/doc/src/sasl_app.xml +++ b/lib/sasl/doc/src/sasl_app.xml @@ -103,13 +103,16 @@ {file,FileName}

Installs sasl_report_file_h in the error logger. All reports go to file FileName, which is a - string.

+ string. The file is opened in write mode with encoding + utf8.

{file,FileName,Modes}

Same as {file,FileName}, except that Modes allows you to specify the modes used for opening the FileName given to the file:open/2 - call. When not specified, Modes defaults to [write]. - Use [append] to have the FileName open in append mode. + call. By default, the file is opened in write mode + with encoding utf8. Use [append] to have + the FileName open in append mode. A different + encoding can also be specified. FileName is a string.

false

No SASL error logger handler is installed.

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