From 65cd0e43158e38a3c42b00e7f591723226d235fb Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Wed, 2 May 2018 17:14:26 +0200 Subject: kernel: Use formatter in simple logger example --- lib/kernel/doc/src/logger_chapter.xml | 37 +++++++---------------------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/lib/kernel/doc/src/logger_chapter.xml b/lib/kernel/doc/src/logger_chapter.xml index 0bc3b37476..88dcfbe8d9 100644 --- a/lib/kernel/doc/src/logger_chapter.xml +++ b/lib/kernel/doc/src/logger_chapter.xml @@ -539,12 +539,8 @@ changing_config(logger:handler_id(),logger:config(),logger:config()) -> {ok,logg -module(myhandler). -export([log/2]). -log(#{msg:={report,R}},_) -> - io:format("~p~n",[R]); -log(#{msg:={string,S}},_) -> - io:put_chars(S); -log(#{msg:={F,A}},_) -> - io:format(F,A). +log(Log,#{formatter:={FModule,FConfig}) -> + io:put_chars(FModule:format(Log,FConfig)).

A simple handler which prints to file could be implemented like @@ -562,18 +558,13 @@ removing_handler(Id,#{myhandler_fd:=Fd}) -> _ = file:close(Fd), ok. -log(#{msg:={report,R}},#{myhandler_fd:=Fd}) -> - io:format(Fd,"~p~n",[R]); -log(#{msg:={string,S}},#{myhandler_fd:=Fd}) -> - io:put_chars(Fd,S); -log(#{msg:={F,A}},#{myhandler_fd:=Fd}) -> - io:format(Fd,F,A). +log(Log,#{myhandler_fd:=Fd,formatter:={FModule,FConfig}}) -> + io:put_chars(Fd,FModule:format(Log,FConfig)). -

Note that none of the above handlers have any overload +

The above handlers do not have any overload protection, and all log events are printed directly from the - client process. Neither do the handlers use the formatter or - in any way add time or other metadata to the printed events.

+ client process.

For examples of overload protection, please refer to the implementation @@ -582,14 +573,7 @@ log(#{msg:={F,A}},#{myhandler_fd:=Fd}) -> .

Below is a simpler example of a handler which logs through one - single process, and uses the default formatter to gain a common - look of the log events.

-

It also uses the metadata field report_cb, if it exists, - to print reports in the way the event issuer suggests. The - formatter will normally do this, but if the handler either has - an own default (as in this example) or if the - given report_cb should not be used at all, then the - handler must take care of this itself.

+ single process.

-module(myhandler). -export([adding_handler/2, removing_handler/1, log/2]). @@ -620,16 +604,9 @@ terminate(Reason,#{fd:=Fd}) -> _ = file:close(Fd), ok. -do_log(Fd,#{msg:={report,R}} = Log, Config) -> - Fun = maps:get(report_cb,Config,fun my_report_cb/1, - {F,A} = Fun(R), - do_log(Fd,Log#{msg=>{F,A},Config); do_log(Fd,Log,#{formatter:={FModule,FConfig}}) -> String = FModule:format(Log,FConfig), io:put_chars(Fd,String). - -my_report_cb(R) -> - {"~p",[R]}. -- cgit v1.2.3 From 30bc7fe1411fc97c733ec9d41ce57f3200a6e542 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Thu, 3 May 2018 09:17:15 +0200 Subject: Add xmllint to travis build --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 88a4c46f77..5499eb22c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,7 @@ addons: - default-jdk - g++ - xsltproc + - libxml2-utils matrix: include: @@ -39,6 +40,7 @@ matrix: - ./scripts/build-otp - ./otp_build tests - make release_docs + - make xmllint - ./scripts/run-smoke-tests before_script: -- cgit v1.2.3