From 395dbad6bcc38c3384840674f40657273b05b14a Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Tue, 8 May 2018 16:13:50 +0200 Subject: logger: Rework configuration of logger Most logger configuration that was possible through kernel application variables have been moved into a common 'logger' application environment in kernel. Now all the configuration possible through the logger API can be done as sys config. The handler started by kernel has been renamed to 'default' instead of logger_std_h. There is a new logger:setup_handlers/1 function that given an application name can be used to setup handlers in other applications. --- lib/kernel/doc/src/logger_chapter.xml | 101 ++++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 4 deletions(-) (limited to 'lib/kernel/doc/src/logger_chapter.xml') diff --git a/lib/kernel/doc/src/logger_chapter.xml b/lib/kernel/doc/src/logger_chapter.xml index 3150c5adb4..484358f392 100644 --- a/lib/kernel/doc/src/logger_chapter.xml +++ b/lib/kernel/doc/src/logger_chapter.xml @@ -248,11 +248,97 @@
Configuration +

Logger can be configured either when the system starts through + configuration parameters, + or at run-time by using the logger + API. The recommended approach is to do the initial configuration in + the sys.config file and then use the API when some configuration + has to be changed at run-time, such as the logging level.

+
- Application environment variables -

See Kernel(6) for - information about the application environment variables that can - be used for configuring logger.

+ Application configuration parameters +

Logger is best configured by using the configuration parameters + of kernel. There are three possible configuration parameters: + logger, + logger_level, + logger_sasl_compatible and + logger_log_progress. + logger_level, logger_sasl_compatible and logger_log_progress are described in the + Kernel Configuration, + while logger is described below.

+
+ + logger +

The logger application configuration parameter is used to configure + three different logger aspects; handlers, logger filters and module levels. + The configuration is a list containing tagged tuples that look like this:

+ + DisableHandler = {handler,default,undefined} + Disable the default handler. This will allow another application + to add its own default handler. See + logger:add_handlers/1 for more details. + AddHandler = {handler,HandlerId,Module,HandlerConfig} + Add a handler as if + logger:add_handler(HandlerId,Module,HandlerConfig) had been + called. + Filters = {filters, FilterDefault, [Filter]}
+ FilterDefault = log | stop
+ Filter = {FilterId, {FilterFun, FilterConfig}}
+ Add the specified + logger filters. Only one entry is allowed of this option. + ModuleLevel + {module_level, Level, [Module]}, + this option configures the + module log level to be used. It is possible to have multiple + module_level entries. +
+

Examples:

+ + +

Output logs into a the file "logs/erlang.log"

+ +[{kernel, + [{logger, + [{handler, default, logger_std_h, + #{ logger_std_h => #{ type => {file,"log/erlang.log"}}}}]}]}]. + +
+ +

Output logs in single line format

+ +[{kernel, + [{logger, + [{handler, default, logger_std_h, + #{ formatter => { logger_formatter,#{ single_line => true}}}}]}]}]. + +
+ +

Add the pid to each log event

+ +[{kernel, + [{logger, + [{handler, default, logger_std_h, + #{ formatter => { logger_formatter, + #{ template => [time," ",pid," ",msg,"\n"]}} + }}]}]}]. + +
+ +

Use a different file for debug logging

+ +[{kernel, + [{logger, + [{handler, default, logger_std_h, + #{ level => error, + logger_std_h => #{ type => {file, "log/erlang.log"}}}}, + {handler, info, logger_std_h, + #{ level => debug, + logger_std_h => #{ type => {file, "log/debug.log"}}}} + ]}]}]. + +
+
+
@@ -330,6 +416,13 @@ logger_formatter, and Extra is it's configuration map.

+ HandlerConfig, term() = term() + + Any keys not listed above are considered to be handler specific + configuration. The configuration of the Kernel handlers can be found in + logger_std_h and + logger_disk_log_h. +

Note that level and filters are obeyed by -- cgit v1.2.3