aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src
diff options
context:
space:
mode:
authorSiri Hansen <[email protected]>2018-05-14 19:06:22 +0200
committerLukas Larsson <[email protected]>2018-05-21 17:43:53 +0200
commitd29fca17a0c053fca2e5961fb146e9aeefb55aa9 (patch)
treeeb6b00cb523b9d2ab1c3bfc180f22f55de6e9492 /lib/kernel/src
parentc2c5e22e0c0f67d0c445113b7908dd07e4e8d4c4 (diff)
downloadotp-d29fca17a0c053fca2e5961fb146e9aeefb55aa9.tar.gz
otp-d29fca17a0c053fca2e5961fb146e9aeefb55aa9.tar.bz2
otp-d29fca17a0c053fca2e5961fb146e9aeefb55aa9.zip
Hide handlers field in logger config map from the API
This field contains the index of all installed handlers. It is internal and can not be altered by the user, and should therefore not be visible.
Diffstat (limited to 'lib/kernel/src')
-rw-r--r--lib/kernel/src/logger.erl17
-rw-r--r--lib/kernel/src/logger_server.erl44
2 files changed, 23 insertions, 38 deletions
diff --git a/lib/kernel/src/logger.erl b/lib/kernel/src/logger.erl
index 7ce4a80bbd..2c7466fdf6 100644
--- a/lib/kernel/src/logger.erl
+++ b/lib/kernel/src/logger.erl
@@ -364,7 +364,8 @@ set_handler_config(HandlerId,Config) ->
-spec get_logger_config() -> {ok,Config} when
Config :: config().
get_logger_config() ->
- logger_config:get(?LOGGER_TABLE,logger).
+ {ok,Config} = logger_config:get(?LOGGER_TABLE,logger),
+ {ok,maps:remove(handlers,Config)}.
-spec get_handler_config(HandlerId) -> {ok,{Module,Config}} | {error,term()} when
HandlerId :: handler_id(),
@@ -445,8 +446,9 @@ i() ->
i(_Action = print) ->
io:put_chars(i(string));
i(_Action = string) ->
- #{logger := #{level := Level, handlers := Handlers,
- filters := Filters, filter_default := FilterDefault},
+ #{logger := #{level := Level,
+ filters := Filters,
+ filter_default := FilterDefault},
handlers := HandlerConfigs,
module_levels := Modules} = i(term),
[io_lib:format("Current logger configuration:~n", []),
@@ -455,16 +457,15 @@ i(_Action = string) ->
io_lib:format(" Filters: ~n", []),
print_filters(4, Filters),
io_lib:format(" Handlers: ~n", []),
- print_handlers([C || {Id, _, _} = C <- HandlerConfigs,
- lists:member(Id, Handlers)]),
+ print_handlers(HandlerConfigs),
io_lib:format(" Level set per module: ~n", []),
print_module_levels(Modules)
];
i(_Action = term) ->
{Logger, Handlers, Modules} = logger_config:get(tid()),
- #{logger=>Logger,
- handlers=>Handlers,
- module_levels=>Modules}.
+ #{logger=>maps:remove(handlers,Logger),
+ handlers=>lists:keysort(1,Handlers),
+ module_levels=>lists:keysort(1,Modules)}.
print_filters(Indent, {Id, {Fun, Config}}) ->
io_lib:format("~sId: ~p~n"
diff --git a/lib/kernel/src/logger_server.erl b/lib/kernel/src/logger_server.erl
index f1b4a21c6a..bd0c325f2b 100644
--- a/lib/kernel/src/logger_server.erl
+++ b/lib/kernel/src/logger_server.erl
@@ -48,23 +48,18 @@ start_link() ->
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
add_handler(Id,Module,Config0) ->
- case sanity_check(logger,handlers,[Id]) of
- ok ->
- try check_mod(Module) of
+ try {check_id(Id),check_mod(Module)} of
+ {ok,ok} ->
+ case sanity_check(Id,Config0) of
ok ->
- case sanity_check(Id,Config0) of
- ok ->
- Default = default_config(Id),
- Config = maps:merge(Default,Config0),
- call({add_handler,Id,Module,Config});
- Error ->
- Error
- end
- catch throw:Error ->
- {error,Error}
- end;
- Error ->
- Error
+ Default = default_config(Id),
+ Config = maps:merge(Default,Config0),
+ call({add_handler,Id,Module,Config});
+ Error ->
+ Error
+ end
+ catch throw:Error ->
+ {error,Error}
end.
remove_handler(HandlerId) ->
@@ -197,7 +192,8 @@ handle_call({update_config,Id,NewConfig}, From, #state{tid=Tid}=State) ->
{reply,Error,State}
end;
handle_call({set_config,logger,Config}, _From, #state{tid=Tid}=State) ->
- Reply = do_set_config(Tid,logger,Config),
+ {ok,#{handlers:=Handlers}} = logger_config:get(Tid,logger),
+ Reply = do_set_config(Tid,logger,Config#{handlers=>Handlers}),
{reply,Reply,State};
handle_call({set_config,HandlerId,Config}, From, #state{tid=Tid}=State) ->
case logger_config:get(Tid,HandlerId) of
@@ -322,8 +318,7 @@ do_set_config(Tid,Id,Config) ->
default_config(logger) ->
#{level=>info,
filters=>[],
- filter_default=>log,
- handlers=>[]};
+ filter_default=>log};
default_config(_) ->
#{level=>info,
filters=>[],
@@ -354,9 +349,6 @@ get_type(Id) ->
check_config(Owner,[{level,Level}|Config]) ->
check_level(Level),
check_config(Owner,Config);
-check_config(logger,[{handlers,Handlers}|Config]) ->
- check_handlers(Handlers),
- check_config(logger,Config);
check_config(Owner,[{filters,Filters}|Config]) ->
check_filters(Filters),
check_config(Owner,Config);
@@ -394,14 +386,6 @@ check_level(Level) ->
throw({invalid_level,Level})
end.
-check_handlers([Id|Handlers]) ->
- check_id(Id),
- check_handlers(Handlers);
-check_handlers([]) ->
- ok;
-check_handlers(Handlers) ->
- throw({invalid_handlers,Handlers}).
-
check_filters([{Id,{Fun,_Args}}|Filters]) when is_atom(Id), is_function(Fun,2) ->
check_filters(Filters);
check_filters([Filter|_]) ->