aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src
diff options
context:
space:
mode:
authorSiri Hansen <[email protected]>2018-05-07 12:02:59 +0200
committerSiri Hansen <[email protected]>2018-05-07 12:02:59 +0200
commitcd832e85a3029162c31659ca174efdf43a08c8d2 (patch)
tree160726aa478bfce1ab6d221dc0b40e5dcfaa33ce /lib/kernel/src
parent4c350d64b85686b731d0888c36159b4d126e5cf1 (diff)
parent3c9e4adff06a3f74513cb6658405e43e674133c1 (diff)
downloadotp-cd832e85a3029162c31659ca174efdf43a08c8d2.tar.gz
otp-cd832e85a3029162c31659ca174efdf43a08c8d2.tar.bz2
otp-cd832e85a3029162c31659ca174efdf43a08c8d2.zip
Merge branch 'siri/logger-fix'
* siri/logger-fix: Change logger callback removing_handler/1 to removing_handler/2 Don't crash logger_server due to unexpected message Add logger:update_process_metadata/1 Improve documentation of logger:set_*_config functions Change return type from logger_formatter:format/2 Improve test of logger_disk_log_h and logger_std_h Update logger documentation Set single_line=true by default in logger_formatter
Diffstat (limited to 'lib/kernel/src')
-rw-r--r--lib/kernel/src/error_logger.erl6
-rw-r--r--lib/kernel/src/logger.erl17
-rw-r--r--lib/kernel/src/logger_disk_log_h.erl4
-rw-r--r--lib/kernel/src/logger_formatter.erl7
-rw-r--r--lib/kernel/src/logger_internal.hrl1
-rw-r--r--lib/kernel/src/logger_server.erl10
-rw-r--r--lib/kernel/src/logger_simple.erl4
-rw-r--r--lib/kernel/src/logger_std_h.erl4
8 files changed, 36 insertions, 17 deletions
diff --git a/lib/kernel/src/error_logger.erl b/lib/kernel/src/error_logger.erl
index 0706220a94..47d0ca5ea3 100644
--- a/lib/kernel/src/error_logger.erl
+++ b/lib/kernel/src/error_logger.erl
@@ -32,7 +32,7 @@
which_report_handlers/0]).
%% logger callbacks
--export([adding_handler/2, removing_handler/1, log/2]).
+-export([adding_handler/2, removing_handler/2, log/2]).
-export([get_format_depth/0, limit_term/1]).
@@ -111,8 +111,8 @@ adding_handler(?MODULE,Config) ->
Error
end.
--spec removing_handler(logger:handler_id()) -> ok.
-removing_handler(?MODULE) ->
+-spec removing_handler(logger:handler_id(),logger:config()) -> ok.
+removing_handler(?MODULE,_Config) ->
stop(),
ok.
diff --git a/lib/kernel/src/logger.erl b/lib/kernel/src/logger.erl
index 943ef8c2d1..5562764204 100644
--- a/lib/kernel/src/logger.erl
+++ b/lib/kernel/src/logger.erl
@@ -44,8 +44,8 @@
%% Misc
-export([compare_levels/2]).
--export([set_process_metadata/1, unset_process_metadata/0,
- get_process_metadata/0]).
+-export([set_process_metadata/1, update_process_metadata/1,
+ unset_process_metadata/0, get_process_metadata/0]).
-export([i/0, i/1]).
-export([setup_standard_handler/0, replace_simple_handler/3]).
-export([limit_term/1, get_format_depth/0, get_max_size/0, get_utc_config/0]).
@@ -390,6 +390,19 @@ set_process_metadata(Meta) when is_map(Meta) ->
set_process_metadata(Meta) ->
erlang:error(badarg,[Meta]).
+-spec update_process_metadata(Meta) -> ok when
+ Meta :: metadata().
+update_process_metadata(Meta) when is_map(Meta) ->
+ case get_process_metadata() of
+ undefined ->
+ set_process_metadata(Meta);
+ Meta0 when is_map(Meta0) ->
+ set_process_metadata(maps:merge(Meta0,Meta)),
+ ok
+ end;
+update_process_metadata(Meta) ->
+ erlang:error(badarg,[Meta]).
+
-spec get_process_metadata() -> Meta | undefined when
Meta :: metadata().
get_process_metadata() ->
diff --git a/lib/kernel/src/logger_disk_log_h.erl b/lib/kernel/src/logger_disk_log_h.erl
index 3b71f936d8..0150fa781a 100644
--- a/lib/kernel/src/logger_disk_log_h.erl
+++ b/lib/kernel/src/logger_disk_log_h.erl
@@ -34,7 +34,7 @@
%% logger callbacks
-export([log/2,
- adding_handler/2, removing_handler/1,
+ adding_handler/2, removing_handler/2,
changing_config/3, swap_buffer/2]).
%%%===================================================================
@@ -223,7 +223,7 @@ check_my_config([]) ->
%%%-----------------------------------------------------------------
%%% Handler being removed
-removing_handler(Name) ->
+removing_handler(Name, _Config) ->
stop(Name).
%%%-----------------------------------------------------------------
diff --git a/lib/kernel/src/logger_formatter.erl b/lib/kernel/src/logger_formatter.erl
index 386e7832e2..8e954f8d98 100644
--- a/lib/kernel/src/logger_formatter.erl
+++ b/lib/kernel/src/logger_formatter.erl
@@ -29,7 +29,7 @@
%%%-----------------------------------------------------------------
%%% API
--spec format(Log,Config) -> String when
+-spec format(Log,Config) -> unicode:chardata() when
Log :: logger:log(),
Config :: #{single_line=>boolean(),
legacy_header=>boolean(),
@@ -38,8 +38,7 @@
max_size=>pos_integer() | unlimited,
depth=>pos_integer() | unlimited,
template=>template(),
- utc=>boolean()},
- String :: string().
+ utc=>boolean()}.
format(#{level:=Level,msg:=Msg0,meta:=Meta},Config0)
when is_map(Config0) ->
Config = add_default_config(Config0),
@@ -263,7 +262,7 @@ utcstr(_) -> "".
add_default_config(#{utc:=_}=Config0) ->
Default =
#{legacy_header=>false,
- single_line=>false,
+ single_line=>true,
chars_limit=>unlimited},
MaxSize = get_max_size(maps:get(max_size,Config0,false)),
Depth = get_depth(maps:get(depth,Config0,false)),
diff --git a/lib/kernel/src/logger_internal.hrl b/lib/kernel/src/logger_internal.hrl
index 82df499c2b..8c0fc2725d 100644
--- a/lib/kernel/src/logger_internal.hrl
+++ b/lib/kernel/src/logger_internal.hrl
@@ -31,6 +31,7 @@
{no_domain,{fun logger_filters:domain/2,{log,no_domain,[]}}}]).
-define(DEFAULT_FORMATTER,logger_formatter).
-define(DEFAULT_FORMAT_CONFIG,#{legacy_header=>true,
+ single_line=>false,
template=>?DEFAULT_FORMAT_TEMPLATE_HEADER}).
-define(DEFAULT_FORMAT_TEMPLATE_HEADER,
[{logger_formatter,header},"\n",msg,"\n"]).
diff --git a/lib/kernel/src/logger_server.erl b/lib/kernel/src/logger_server.erl
index 6ef3b8582a..a7f302ac8f 100644
--- a/lib/kernel/src/logger_server.erl
+++ b/lib/kernel/src/logger_server.erl
@@ -158,7 +158,7 @@ handle_call({remove_handler,HandlerId}, _From, #state{tid=Tid}=State) ->
Handlers0 = maps:get(handlers,Config,[]),
Handlers = lists:delete(HandlerId,Handlers0),
%% inform the handler
- _ = call_h(Module,removing_handler,[HandlerId],ok),
+ _ = call_h(Module,removing_handler,[HandlerId,Config],ok),
do_set_config(Tid,logger,Config#{handlers=>Handlers}),
logger_config:delete(Tid,HandlerId),
ok;
@@ -234,7 +234,13 @@ handle_info({log,Level,Report,Meta}, State) ->
{noreply, State};
handle_info({Ref,_Reply},State) when is_reference(Ref) ->
%% Assuming this is a timed-out gen_server reply - ignoring
- {noreply, State}.
+ {noreply, State};
+handle_info(Unexpected,State) ->
+ ?LOG_INTERNAL(debug,
+ [{logger,got_unexpected_message},
+ {process,?SERVER},
+ {message,Unexpected}]),
+ {noreply,State}.
terminate(_Reason, _State) ->
ok.
diff --git a/lib/kernel/src/logger_simple.erl b/lib/kernel/src/logger_simple.erl
index 23ff6ccd2e..a1b427b96c 100644
--- a/lib/kernel/src/logger_simple.erl
+++ b/lib/kernel/src/logger_simple.erl
@@ -19,7 +19,7 @@
%%
-module(logger_simple).
--export([adding_handler/2, removing_handler/1, log/2]).
+-export([adding_handler/2, removing_handler/2, log/2]).
-export([get_buffer/0]).
%% This module implements a simple handler for logger. It is the
@@ -63,7 +63,7 @@ adding_handler(?MODULE,Config) ->
{error,{handler_process_name_already_exists,?MODULE}}
end.
-removing_handler(?MODULE) ->
+removing_handler(?MODULE,_Config) ->
case whereis(?MODULE) of
undefined ->
ok;
diff --git a/lib/kernel/src/logger_std_h.erl b/lib/kernel/src/logger_std_h.erl
index cbc9db372c..31edcfea8b 100644
--- a/lib/kernel/src/logger_std_h.erl
+++ b/lib/kernel/src/logger_std_h.erl
@@ -35,7 +35,7 @@
terminate/2, code_change/3]).
%% logger callbacks
--export([log/2, adding_handler/2, removing_handler/1,
+-export([log/2, adding_handler/2, removing_handler/2,
changing_config/3, swap_buffer/2]).
%%%===================================================================
@@ -207,7 +207,7 @@ check_my_config([]) ->
%%%-----------------------------------------------------------------
%%% Handler being removed
-removing_handler(Name) ->
+removing_handler(Name,_Config) ->
stop(Name).
%%%-----------------------------------------------------------------