From 6fae4fbd3650366730d35988ee588c32848dbecc Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Wed, 3 Oct 2018 12:21:23 +0200 Subject: [logger] Add handler callback filter_config/1 This function is called when a logger API function for fetching handler configuration is called. The point is to allow the handler to remove internal data fields that it might have stored in the configuration database, before returning the handler configuration to the caller. An example of such internal data are the 'handler_pid' and 'mode_tab' fields that logger_std_h and logger_disk_log_h store in their configuration maps. --- lib/kernel/doc/src/logger.xml | 20 ++++++++++++++++++++ lib/kernel/doc/src/logger_chapter.xml | 12 ++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'lib/kernel/doc/src') diff --git a/lib/kernel/doc/src/logger.xml b/lib/kernel/doc/src/logger.xml index aa6e17f27b..2bcf137299 100644 --- a/lib/kernel/doc/src/logger.xml +++ b/lib/kernel/doc/src/logger.xml @@ -1122,6 +1122,26 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(), Meta)). + + HModule:filter_config(Config) -> FilteredConfig + Remove internal data from configuration. + + Config = FilteredConfig = + handler_config() + + +

This callback function is optional.

+

The function is called when one of the Logger API functions + for fetching the handler configuration is called, for + example + + logger:get_handler_config/1.

+

It allows the handler to remove internal data fields from + its configuration data before it is returned to the + caller.

+
+
+ HModule:log(LogEvent, Config) -> void() Log the given log event. diff --git a/lib/kernel/doc/src/logger_chapter.xml b/lib/kernel/doc/src/logger_chapter.xml index 777c37058e..1870d2ab79 100644 --- a/lib/kernel/doc/src/logger_chapter.xml +++ b/lib/kernel/doc/src/logger_chapter.xml @@ -384,8 +384,8 @@ logger:debug(#{got => connection_request, id => Id, state => State},

In addition to the mandatory callback function log/2, a handler module can export the optional callback - functions adding_handler/1, changing_config/3 - and removing_handler/1. See + functions adding_handler/1, changing_config/3, + filter_config/1, and removing_handler/1. See section Handler Callback Functions in the logger(3) manual page for more information about these function.

@@ -1029,6 +1029,7 @@ ok adding_handler(Config) removing_handler(Config) changing_config(SetOrUpdate, OldConfig, NewConfig) + filter_config(Config)

When a handler is added, by for example a call to @@ -1052,6 +1053,13 @@ ok calls HModule:changing_config(SetOrUpdate, OldConfig, NewConfig). If this function returns {ok,NewConfig1}, Logger writes NewConfig1 to the configuration database.

+

When + logger:get_config/0 or + + logger:get_handler_config/0,1 is called, + Logger calls HModule:filter_config(Config). This function + must return the handler configuration where internal data is + removed.

A simple handler that prints to the terminal can be implemented as follows:

-- cgit v1.2.3