From 05e1548e5b452d4bfe3bc6837a1a1b51a6367f72 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Tue, 24 Apr 2018 14:55:29 +0200 Subject: Remove error_logger process and add logger process --- lib/sasl/doc/src/sasl_app.xml | 183 ++++++++++++++++++++++++----------------- lib/sasl/src/sasl.app.src | 3 +- lib/sasl/src/sasl.erl | 90 +++++++++++--------- lib/sasl/src/systools_make.erl | 8 +- 4 files changed, 168 insertions(+), 116 deletions(-) (limited to 'lib/sasl') diff --git a/lib/sasl/doc/src/sasl_app.xml b/lib/sasl/doc/src/sasl_app.xml index e0693fcb60..48b0b8eafb 100644 --- a/lib/sasl/doc/src/sasl_app.xml +++ b/lib/sasl/doc/src/sasl_app.xml @@ -34,12 +34,9 @@

The SASL application provides the following services:

alarm_handler - rb release_handler systools -

The SASL application also includes error_logger event - handlers for formatting SASL error and crash reports.

The SASL application in OTP has nothing to do with "Simple Authentication and Security Layer" (RFC 4422).

@@ -47,51 +44,109 @@
- Error Logger Event Handlers -

The following error logger event handlers are used by - the SASL application.

+ Configuration +

The following configuration parameters are defined for the SASL + application. For more information about configuration parameters, see + app(4) in Kernel.

+

All configuration parameters are optional.

+ + + +

Specifies the program to be used when restarting the system + during release installation. Default is + $OTP_ROOT/bin/start.

+
+ + +

Specifies the nodes used by this node to read/write release + information. This parameter is ignored if parameter + client_directory is not set.

+
+ + +

This parameter specifies the client directory at the master + nodes. For details, see + Release Handling + in OTP Design Principles. This parameter is + ignored if parameter masters is not set.

+
+ + +

Indicates if the Erlang emulator is statically installed. A + node with a static emulator cannot switch dynamically to a + new emulator, as the executable files are written into memory + statically. This parameter is ignored if parameters masters + and client_directory are not set.

+
+ + +

Indicates where the releases directory is located. + The release handler writes all its files to this directory. + If this parameter is not set, the OS environment parameter + RELDIR is used. By default, this is + $OTP_ROOT/releases.

+
+ + +

If set to true, all dates in textual log outputs are + displayed in Universal Coordinated Time with the string + UTC appended.

+
+
+
+ +
+ Deprecated Error Logger Event Handlers and Configuration +

In OTP-21, a new API for logging was added to Erlang/OTP. The + old error_logger event manager, and event handlers + running on this manager, will still work, but they are not used + by default.

+

The error logger event handlers sasl_report_tty_h + and sasl_report_file_h, were earliger used for printing + the so called SASL reports, i.e. supervisor + reports, crash reports, and progress + reports. These reports are now also printed by the standard + logger handler started by the Kernel application. Progress + reports are by default stopped by a filter, but can easily be + added by setting the Kernel configuration + parameter logger_log_progress=true.

+

If the old error logger event handlers are still desired, they + must be added by + calling error_logger:add_report_handler/1,2.

sasl_report_tty_h

Formats and writes supervisor reports, crash reports, and progress reports to stdio. This error logger event handler uses - error_logger_format_depth - in the Kernel application to limit how much detail is - printed in crash and supervisor reports.

+ logger_format_depth + in the Kernel application to limit how much detail is printed + in crash and supervisor reports. If logger_format_depth + is not set, it uses the old error_logger_format_depth + instead.

sasl_report_file_h

Formats and writes supervisor reports, crash report, and progress report to a single file. This error logger event handler uses - error_logger_format_depth - in the Kernel application to limit the details - printed in crash and supervisor reports.

-
- log_mf_h - -

This error logger writes all events sent to the - error logger to disk. Multiple files and log rotation are - used. For efficiency reasons, each event is written as a - binary. For more information about this handler, - see the STDLIB Reference - Manual.

-

To activate this event handler, three SASL - configuration parameters must be set, - error_logger_mf_dir, error_logger_mf_maxbytes, - and error_logger_mf_maxfiles. The next section provides - more information about the configuration parameters.

+ logger_format_depth + in the Kernel application to limit the details printed in + crash and supervisor reports. If logger_format_depth is + not set, it uses the old error_logger_format_depth + instead.

-
- -
- Configuration -

The following configuration parameters are defined for the SASL - application. For more information about configuration parameters, see - app(4) in Kernel.

-

All configuration parameters are optional.

+

A similar behaviour, but still using the new logger API, can be + obtained by setting the Kernel application environment + variable logger_sasl_compatible=true. This will add a + second instance of the standard logger handler + named sasl_h, which will only print the SASL reports. No + SASL reports will then be printed by the Kernel logger + handler.

+

The sasl_h handler will be configured according to the + values of the following SASL application environment + variables.

@@ -124,6 +179,19 @@ sasl_error_logger to error reports or progress reports, or both. Default is all.

+
+ +

The error logger event handler log_mf_h can also still + be used. This event handler writes all events sent to + the error logger to disk. Multiple files and log rotation are + used. For efficiency reasons, each event is written as a + binary. For more information about this handler, + see the STDLIB Reference + Manual.

+

To activate this event handler, three SASL configuration + parameters must be + set:

+

Specifies in which directory log_mf_h is to store @@ -142,49 +210,12 @@ this parameter is undefined, the log_mf_h handler is not installed.

- - -

Specifies the program to be used when restarting the system - during release installation. Default is - $OTP_ROOT/bin/start.

-
- - -

Specifies the nodes used by this node to read/write release - information. This parameter is ignored if parameter - client_directory is not set.

-
- - -

This parameter specifies the client directory at the master - nodes. For details, see - Release Handling - in OTP Design Principles. This parameter is - ignored if parameter masters is not set.

-
- - -

Indicates if the Erlang emulator is statically installed. A - node with a static emulator cannot switch dynamically to a - new emulator, as the executable files are written into memory - statically. This parameter is ignored if parameters masters - and client_directory are not set.

-
- - -

Indicates where the releases directory is located. - The release handler writes all its files to this directory. - If this parameter is not set, the OS environment parameter - RELDIR is used. By default, this is - $OTP_ROOT/releases.

-
- - -

If set to true, all dates in textual log outputs are - displayed in Universal Coordinated Time with the string - UTC appended.

-
+

The new + logger_disk_log_h might be an alternative + to log_mf_h if log rotation is desired. This does, + however, write the log events in clear text and not as binaries.

+
diff --git a/lib/sasl/src/sasl.app.src b/lib/sasl/src/sasl.app.src index 1e8e58a978..60d08ffa54 100644 --- a/lib/sasl/src/sasl.app.src +++ b/lib/sasl/src/sasl.app.src @@ -40,8 +40,7 @@ ]}, {registered, [sasl_sup, alarm_handler, release_handler]}, {applications, [kernel, stdlib]}, - {env, [{sasl_error_logger, tty}, - {errlog_type, all}]}, + {env, []}, {mod, {sasl, []}}, {runtime_dependencies, ["tools-2.6.14","stdlib-3.4","kernel-5.3", "erts-9.0"]}]}. diff --git a/lib/sasl/src/sasl.erl b/lib/sasl/src/sasl.erl index 24afaee183..657eb6688a 100644 --- a/lib/sasl/src/sasl.erl +++ b/lib/sasl/src/sasl.erl @@ -31,45 +31,52 @@ %%%----------------------------------------------------------------- -behaviour(application). --record(state, {sasl_error_logger, error_logger_mf}). +-record(state, {sasl_logger, error_logger_mf}). start(_, []) -> - Handler = get_sasl_error_logger(), - Type = get_sasl_error_logger_type(), + {Dest,Level} = get_logger_info(), Mf = get_error_logger_mf(), - add_sasl_error_logger(Handler, Type), + add_sasl_logger(Dest, Level), add_error_logger_mf(Mf), - State = #state{sasl_error_logger = Handler, error_logger_mf = Mf}, + State = #state{sasl_logger = Dest, error_logger_mf = Mf}, case supervisor:start_link({local, sasl_sup}, sasl, []) of {ok, Pid} -> {ok, Pid, State}; Error -> Error end. stop(State) -> - delete_sasl_error_logger(State#state.sasl_error_logger), + delete_sasl_logger(State#state.sasl_logger), delete_error_logger_mf(State#state.error_logger_mf). %%----------------------------------------------------------------- %% Internal functions %%----------------------------------------------------------------- -get_sasl_error_logger() -> +get_logger_info() -> + case application:get_env(kernel, logger_sasl_compatible) of + {ok,true} -> + {get_logger_dest(),get_logger_level()}; + _ -> + {std,undefined} + end. + +get_logger_dest() -> case application:get_env(sasl, sasl_error_logger) of - {ok, false} -> undefined; - {ok, tty} -> tty; - {ok, {file, File}} when is_list(File) -> {file, File, [write]}; - {ok, {file, File, Modes}} when is_list(File), is_list(Modes) -> - {file, File, Modes}; - {ok, Bad} -> exit({bad_config, {sasl, {sasl_error_logger, Bad}}}); - _ -> undefined + {ok, false} -> undefined; + {ok, tty} -> standard_io; + {ok, {file, File}} when is_list(File) -> {file, File}; + {ok, {file, File, Modes}} when is_list(File), is_list(Modes) -> + {file, File, Modes}; + {ok, Bad} -> exit({bad_config, {sasl, {sasl_logger_dest, Bad}}}); + undefined -> standard_io end. -get_sasl_error_logger_type() -> +get_logger_level() -> case application:get_env(sasl, errlog_type) of - {ok, error} -> error; - {ok, progress} -> progress; - {ok, all} -> all; - {ok, Bad} -> exit({bad_config, {sasl, {errlog_type, Bad}}}); - _ -> all + {ok, error} -> error; + {ok, progress} -> info; + {ok, all} -> info; + {ok, Bad} -> exit({bad_config, {sasl, {errlog_type, Bad}}}); + _ -> info end. get_error_logger_mf() -> @@ -119,23 +126,32 @@ get_mf_maxf() -> {ok, Bad} -> exit({bad_config, {sasl, {error_logger_mf_maxfiles, Bad}}}) end. -add_sasl_error_logger(undefined, _Type) -> ok; -add_sasl_error_logger(Handler, Type) -> - error_logger:add_report_handler(mod(Handler), args(Handler, Type)). - -delete_sasl_error_logger(undefined) -> ok; -delete_sasl_error_logger(Type) -> - error_logger:delete_report_handler(mod(Type)). - -mod(tty) -> sasl_report_tty_h; -mod({file, _File, _Modes}) -> sasl_report_file_h. - -args({file, File, Modes}, Type) -> {File, Modes, type(Type)}; -args(_, Type) -> type(Type). - -type(error) -> error; -type(progress) -> progress; -type(_) -> all. +add_sasl_logger(undefined, _Level) -> ok; +add_sasl_logger(std, undefined) -> ok; +add_sasl_logger(Dest, Level) -> + FC0 = #{legacy_header=>true, + template=>[{logger_formatter,header},"\n",msg,"\n"]}, + FC = case application:get_env(sasl,utc_log) of + {ok,Bool} when is_boolean(Bool) -> + FC0#{utc=>Bool}; + _ -> + FC0 + end, + ok = logger:add_handler(sasl_h,logger_std_h, + #{level=>Level, + filter_default=>stop, + filters=> + [{sasl_domain, + {fun logger_filters:domain/2, + {log,equals,[beam,erlang,otp,sasl]}}}], + logger_std_h=>#{type=>Dest}, + formatter=>{logger_formatter,FC}}). + +delete_sasl_logger(undefined) -> ok; +delete_sasl_logger(std) -> ok; +delete_sasl_logger(_Type) -> + _ = logger:remove_handler(sasl_h), + ok. add_error_logger_mf(undefined) -> ok; add_error_logger_mf({Dir, MaxB, MaxF}) -> diff --git a/lib/sasl/src/systools_make.erl b/lib/sasl/src/systools_make.erl index a9e8bcecfa..f4b1b54fd1 100644 --- a/lib/sasl/src/systools_make.erl +++ b/lib/sasl/src/systools_make.erl @@ -1546,6 +1546,12 @@ mandatory_modules() -> gen_server, heart, kernel, + logger, + logger_filters, + logger_server, + logger_backend, + logger_config, + logger_simple, lists, proc_lib, supervisor @@ -1570,7 +1576,7 @@ preloaded() -> kernel_processes() -> [{heart, heart, start, []}, - {error_logger, error_logger, start_link, []}, + {logger, logger_server, start_link, []}, {application_controller, application_controller, start, fun(Appls) -> [{_,App}] = filter(fun({{kernel,_},_App}) -> true; -- cgit v1.2.3