From f38163aa64547e09f99e362edefeda713e06ddb7 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Mon, 21 May 2018 17:45:21 +0200 Subject: Remove HandlerId from handler callback functions and add it to Config --- lib/kernel/doc/src/logger.xml | 23 +++++++++++++---------- lib/kernel/doc/src/logger_chapter.xml | 26 +++++++++++++------------- 2 files changed, 26 insertions(+), 23 deletions(-) (limited to 'lib/kernel/doc/src') diff --git a/lib/kernel/doc/src/logger.xml b/lib/kernel/doc/src/logger.xml index 6e50473fa8..d6576db6f3 100644 --- a/lib/kernel/doc/src/logger.xml +++ b/lib/kernel/doc/src/logger.xml @@ -881,11 +881,9 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)). - HModule:adding_handler(HandlerId,Config1) -> {ok,Config2} | {error,Reason} + HModule:adding_handler(Config1) -> {ok,Config2} | {error,Reason} An instance of this handler is about to be added. - HandlerId = - handler_id() Config1 = Config2 = config() Reason = term() @@ -895,6 +893,8 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)).

The function is called when an new handler is about to be added, and the purpose is to verify the configuration and initiate all resources needed by the handler.

+

The handler identity is associated with the id key + in Config1.

If everything succeeds, the callback function can add possible default values or internal state values to the configuration, and return the adjusted map @@ -905,11 +905,9 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)). - HModule:changing_config(HandlerId,Config1,Config2) -> {ok,Config3} | {error,Reason} + HModule:changing_config(Config1,Config2) -> {ok,Config3} | {error,Reason} The configuration for this handler is about to change. - HandlerId = - handler_id() Config1 = Config2 = Config3 = config() Reason = term() @@ -921,6 +919,8 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)). the new configuration.

Config1 is the existing configuration and Config2 is the new configuration.

+

The handler identity is associated with the id key + in Config1.

If everything succeeds, the callback function must return a possibly adjusted configuration in {ok,Config3}.

If the configuration is faulty, the callback function must @@ -942,6 +942,8 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)).

The function is called when all global filters and all handler filters for the handler in question have passed for the given log event.

+

The handler identity is associated with the id key + in Config.

The handler must log the event.

The return value from this function is ignored by Logger.

@@ -949,11 +951,9 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)).
- HModule:removing_handler(HandlerId,Config) -> ok + HModule:removing_handler(Config) -> ok The given handler is about to be removed. - HandlerId = - handler_id() Config = config() @@ -961,7 +961,10 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)).

This callback function is optional.

The function is called when a handler is about to be removed, and the purpose is to release all resources used by - the handler. The return value is ignored by Logger.

+ the handler.

+

The handler identity is associated with the id key + in Config.

+

The return value is ignored by Logger.

diff --git a/lib/kernel/doc/src/logger_chapter.xml b/lib/kernel/doc/src/logger_chapter.xml index 1195808160..78c595d521 100644 --- a/lib/kernel/doc/src/logger_chapter.xml +++ b/lib/kernel/doc/src/logger_chapter.xml @@ -268,7 +268,7 @@

In addition to the mandatory callback function log/2, a handler module can export the optional callback - functions adding_handler/2, changing_config/3 + functions adding_handler/1, changing_config/2 and removing_handler/1. See section Handler Callback Functions in the logger(3) manual for more @@ -738,22 +738,22 @@ ok log(logger:log(),logger:config()) ->ok

It may also implement the following callbacks:

-adding_handler(logger:handler_id(),logger:config()) -> {ok,logger:config()} | {error,term()} -removing_handler(logger:handler_id(),logger:config()) -> ok -changing_config(logger:handler_id(),logger:config(),logger:config()) -> {ok,logger:config()} | {error,term()} +adding_handler(logger:config()) -> {ok,logger:config()} | {error,term()} +removing_handler(logger:config()) -> ok +changing_config(logger:config(),logger:config()) -> {ok,logger:config()} | {error,term()}

When logger:add_handler(Id,Module,Config) is called, Logger - will first call HModule:adding_handler(Id,Config), and if it + will first call HModule:adding_handler(Config), and if it returns {ok,NewConfig}, NewConfig is written to the configuration database. After this, the handler may receive log events as calls to HModule:log/2.

A handler can be removed by calling logger:remove_handler(Id). Logger will call - HModule:removing_handler(Id,Config), and then remove the + HModule:removing_handler(Config), and then remove the handler's configuration from the configuration database.

When logger:set_handler_config/2,3 or logger:update_handler_config/2 are called, Logger - calls HModule:changing_config(Id,OldConfig,NewConfig). If + calls HModule:changing_config(OldConfig,NewConfig). If this function returns {ok,NewConfig}, NewConfig is written to the configuration database.

@@ -771,14 +771,14 @@ log(Log,#{formatter:={FModule,FConfig}) -> this:

-module(myhandler). --export([adding_handler/2, removing_handler/2, log/2]). +-export([adding_handler/1, removing_handler/1, log/2]). -export([init/1, handle_call/3, handle_cast/2, terminate/2]). -adding_handler(Id,Config) -> +adding_handler(Config) -> {ok,Fd} = file:open(File,[append,{encoding,utf8}]), {ok,Config#{myhandler_fd=>Fd}}. -removing_handler(Id,#{myhandler_fd:=Fd}) -> +removing_handler(#{myhandler_fd:=Fd}) -> _ = file:close(Fd), ok. @@ -800,14 +800,14 @@ log(Log,#{myhandler_fd:=Fd,formatter:={FModule,FConfig}}) -> single process.

-module(myhandler). --export([adding_handler/2, removing_handler/2, log/2]). +-export([adding_handler/1, removing_handler/1, log/2]). -export([init/1, handle_call/3, handle_cast/2, terminate/2]). -adding_handler(Id,Config) -> +adding_handler(Config) -> {ok,Pid} = gen_server:start(?MODULE,Config), {ok,Config#{myhandler_pid=>Pid}}. -removing_handler(Id,#{myhandler_pid:=Pid}) -> +removing_handler(#{myhandler_pid:=Pid}) -> gen_server:stop(Pid). log(Log,#{myhandler_pid:=Pid} = Config) -> -- cgit v1.2.3