From 8fed5e01980996cd34be6e27370eed74b5c0ed5d Mon Sep 17 00:00:00 2001
From: Siri Hansen
Date: Mon, 18 Jun 2018 17:37:27 +0200
Subject: [logger] Improve spec for set_handler_config/3 and
set_primary_config/2
Specify which keys and associated values are allowed.
---
lib/kernel/doc/src/logger.xml | 115 +++++++++++++++++++++++++-----------------
lib/kernel/src/logger.erl | 31 +++++++++---
2 files changed, 95 insertions(+), 51 deletions(-)
(limited to 'lib')
diff --git a/lib/kernel/doc/src/logger.xml b/lib/kernel/doc/src/logger.xml
index 33f1919de0..b1321a93dc 100644
--- a/lib/kernel/doc/src/logger.xml
+++ b/lib/kernel/doc/src/logger.xml
@@ -97,46 +97,6 @@ logger:error("error happened because: ~p", [Reason]). % Without macro
-
-
-
- Primary configuration data for Logger. The following
- default values apply:
-
- - level => info
- - filter_default => log
- - filters => []
-
-
-
-
-
-
- Handler configuration data for Logger. The following
- default values apply:
-
- - level => all
- - filter_default => log
- - filters => []
- - formatter => {logger_formatter, DefaultFormatterConfig}
-
- In addition to these, the following fields are
- automatically inserted by Logger, values taken from the
- two first parameters
- to add_handler/3:
-
- - id => HandlerId
- - module => Module
-
- Handler specific configuration data is inserted by the
- handler callback itself, in a sub structure associated with
- the field named config.
- See the
- logger_formatter(3) manual page for
- information about the default configuration for this
- formatter.
-
-
@@ -171,6 +131,39 @@ logger:error("error happened because: ~p", [Reason]). % Without macro
for an example of a formatter implementation.
+
+
+
+ Handler configuration data for Logger. The following
+ default values apply:
+
+ - level => all
+ - filter_default => log
+ - filters => []
+ - formatter => {logger_formatter, DefaultFormatterConfig}
+
+ In addition to these, the following fields are
+ automatically inserted by Logger, values taken from the
+ two first parameters
+ to add_handler/3:
+
+ - id => HandlerId
+ - module => Module
+
+ These are read-only and cannot be changed in runtime.
+ Handler specific configuration data is inserted by the
+ handler callback itself, in a sub structure associated with
+ the field named config. See
+ the logger_std_h(3)
+ and logger_disk_log_h
+ manual pages for information about the specifc configuration
+ for these handlers.
+ See the
+ logger_formatter(3) manual page for
+ information about the default configuration for this
+ formatter.
+
+
@@ -248,6 +241,18 @@ logger:error("error happened because: ~p", [Reason]). % Without macro
+
+
+
+ Primary configuration data for Logger. The following
+ default values apply:
+
+ - level => info
+ - filter_default => log
+ - filters => []
+
+
+
@@ -690,15 +695,30 @@ start(_, []) ->
-
+
+
+
+
+
Add or update configuration data for the specified
handler.
+
+
+
+
+
+
+
Add or update configuration data for the specified
handler. If the given Key already
exists, its associated value will be changed
- to Value. If it does not exist, it will
+ to the given value. If it does not exist, it will
be added.
+ See the definition of
+ the
+ handler_config() type for more
+ information about the different parameters.
@@ -721,13 +741,18 @@ start(_, []) ->
-
+
+
+
Add or update primary configuration data for Logger.
+
+
+
Add or update primary configuration data for Logger. If the
given Key already exists, its associated
- value will be changed to Value. If it
- does not exist, it will be added.
+ value will be changed to the given value. If it does not
+ exist, it will be added.
diff --git a/lib/kernel/src/logger.erl b/lib/kernel/src/logger.erl
index 0a9b1672ec..c78f5372f0 100644
--- a/lib/kernel/src/logger.erl
+++ b/lib/kernel/src/logger.erl
@@ -352,9 +352,12 @@ add_handler(HandlerId,Module,Config) ->
remove_handler(HandlerId) ->
logger_server:remove_handler(HandlerId).
--spec set_primary_config(Key,Value) -> ok | {error,term()} when
- Key :: atom(),
- Value :: term().
+-spec set_primary_config(level,Level) -> ok | {error,term()} when
+ Level :: level() | all | none;
+ (filter_default,FilterDefault) -> ok | {error,term()} when
+ FilterDefault :: log | stop;
+ (filters,Filters) -> ok | {error,term()} when
+ Filters :: [{filter_id(),filter()}].
set_primary_config(Key,Value) ->
logger_server:set_config(primary,Key,Value).
@@ -363,10 +366,26 @@ set_primary_config(Key,Value) ->
set_primary_config(Config) ->
logger_server:set_config(primary,Config).
--spec set_handler_config(HandlerId,Key,Value) -> ok | {error,term()} when
+-spec set_handler_config(HandlerId,level,Level) -> Return when
HandlerId :: handler_id(),
- Key :: atom(),
- Value :: term().
+ Level :: level() | all | none,
+ Return :: ok | {error,term()};
+ (HandlerId,filter_default,FilterDefault) -> Return when
+ HandlerId :: handler_id(),
+ FilterDefault :: log | stop,
+ Return :: ok | {error,term()};
+ (HandlerId,filters,Filters) -> Return when
+ HandlerId :: handler_id(),
+ Filters :: [{filter_id(),filter()}],
+ Return :: ok | {error,term()};
+ (HandlerId,formatter,Formatter) -> Return when
+ HandlerId :: handler_id(),
+ Formatter :: {module(), formatter_config()},
+ Return :: ok | {error,term()};
+ (HandlerId,config,Config) -> Return when
+ HandlerId :: handler_id(),
+ Config :: term(),
+ Return :: ok | {error,term()}.
set_handler_config(HandlerId,Key,Value) ->
logger_server:set_config(HandlerId,Key,Value).
--
cgit v1.2.3