aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src
diff options
context:
space:
mode:
authorSiri Hansen <[email protected]>2019-01-10 16:33:04 +0100
committerSiri Hansen <[email protected]>2019-01-16 09:59:24 +0100
commit48cb63e5ba6ca42c180e6471f393254acfe322ec (patch)
treedeb03f121d7b0f428461f5e6200d946cee82e7ab /lib/kernel/src
parentb387ef2366f92417bcec81e461539844750fc18a (diff)
downloadotp-48cb63e5ba6ca42c180e6471f393254acfe322ec.tar.gz
otp-48cb63e5ba6ca42c180e6471f393254acfe322ec.tar.bz2
otp-48cb63e5ba6ca42c180e6471f393254acfe322ec.zip
[logger] Store proxy config in logger ets table
This is to ensure that logger_proxy gets the same config after a restart.
Diffstat (limited to 'lib/kernel/src')
-rw-r--r--lib/kernel/src/logger.erl14
-rw-r--r--lib/kernel/src/logger_config.erl8
-rw-r--r--lib/kernel/src/logger_internal.hrl1
-rw-r--r--lib/kernel/src/logger_proxy.erl2
-rw-r--r--lib/kernel/src/logger_server.erl26
5 files changed, 39 insertions, 12 deletions
diff --git a/lib/kernel/src/logger.erl b/lib/kernel/src/logger.erl
index f05e756fd0..abdd9a9ceb 100644
--- a/lib/kernel/src/logger.erl
+++ b/lib/kernel/src/logger.erl
@@ -438,11 +438,8 @@ set_handler_config(HandlerId,Config) ->
-spec set_proxy_config(Config) -> ok | {error,term()} when
Config :: olp_config().
-set_proxy_config(Config) when is_map(Config) ->
- Defaults = logger_proxy:get_default_config(),
- logger_olp:set_opts(logger_proxy,maps:merge(Defaults,Config));
set_proxy_config(Config) ->
- {error,{invalid_config,Config}}.
+ logger_server:set_config(proxy,Config).
-spec update_primary_config(Config) -> ok | {error,term()} when
Config :: primary_config().
@@ -480,10 +477,8 @@ update_handler_config(HandlerId,Config) ->
-spec update_proxy_config(Config) -> ok | {error,term()} when
Config :: olp_config().
-update_proxy_config(Config) when is_map(Config) ->
- logger_olp:set_opts(logger_proxy,Config);
update_proxy_config(Config) ->
- {error,{invalid_config,Config}}.
+ logger_server:update_config(proxy,Config).
-spec get_primary_config() -> Config when
Config :: primary_config().
@@ -521,7 +516,8 @@ get_handler_ids() ->
-spec get_proxy_config() -> Config when
Config :: olp_config().
get_proxy_config() ->
- logger_olp:get_opts(logger_proxy).
+ {ok,Config} = logger_config:get(?LOGGER_TABLE,proxy),
+ Config.
-spec update_formatter_config(HandlerId,FormatterConfig) ->
ok | {error,term()} when
@@ -717,7 +713,7 @@ add_handlers(kernel) ->
undefined ->
add_handlers(kernel,Env);
Opts ->
- case logger_olp:set_opts(logger_proxy,Opts) of
+ case set_proxy_config(Opts) of
ok -> add_handlers(kernel,Env);
{error, Reason} -> {error,{bad_proxy_config,Reason}}
end
diff --git a/lib/kernel/src/logger_config.erl b/lib/kernel/src/logger_config.erl
index 5e9faf332c..5024d20cfe 100644
--- a/lib/kernel/src/logger_config.erl
+++ b/lib/kernel/src/logger_config.erl
@@ -66,6 +66,8 @@ get(Tid,What) ->
case ets:lookup(Tid,table_key(What)) of
[{_,_,Config}] ->
{ok,Config};
+ [{_,Config}] when What=:=proxy ->
+ {ok,Config};
[] ->
{error,{not_found,What}}
end.
@@ -79,10 +81,15 @@ get(Tid,What,Level) ->
[Data] -> {ok,Data}
end.
+create(Tid,proxy,Config) ->
+ ets:insert(Tid,{table_key(proxy),Config});
create(Tid,What,Config) ->
LevelInt = level_to_int(maps:get(level,Config)),
ets:insert(Tid,{table_key(What),LevelInt,Config}).
+set(Tid,proxy,Config) ->
+ ets:insert(Tid,{table_key(proxy),Config}),
+ ok;
set(Tid,What,Config) ->
LevelInt = level_to_int(maps:get(level,Config)),
%% Should do this only if the level has actually changed. Possibly
@@ -148,5 +155,6 @@ int_to_level(?LOG_ALL) -> all.
%%%-----------------------------------------------------------------
%%% Internal
+table_key(proxy) -> ?PROXY_KEY;
table_key(primary) -> ?PRIMARY_KEY;
table_key(HandlerId) -> {?HANDLER_KEY,HandlerId}.
diff --git a/lib/kernel/src/logger_internal.hrl b/lib/kernel/src/logger_internal.hrl
index 318fe6b037..e53922e5d3 100644
--- a/lib/kernel/src/logger_internal.hrl
+++ b/lib/kernel/src/logger_internal.hrl
@@ -19,6 +19,7 @@
%%
-include_lib("kernel/include/logger.hrl").
-define(LOGGER_TABLE,logger).
+-define(PROXY_KEY,'$proxy_config$').
-define(PRIMARY_KEY,'$primary_config$').
-define(HANDLER_KEY,'$handler_config$').
-define(LOGGER_META_KEY,'$logger_metadata$').
diff --git a/lib/kernel/src/logger_proxy.erl b/lib/kernel/src/logger_proxy.erl
index 8ac86f17e9..24b293805c 100644
--- a/lib/kernel/src/logger_proxy.erl
+++ b/lib/kernel/src/logger_proxy.erl
@@ -69,7 +69,7 @@ start_link() ->
%%
%% Burst limit is disabled, since this is only a proxy and we
%% don't want to limit bursts twice (here and in the handler).
- logger_olp:start_link(?SERVER,?MODULE,[],get_default_config()).
+ logger_olp:start_link(?SERVER,?MODULE,[],logger:get_proxy_config()).
%% Fun used for restarting this process after it has been killed due
%% to overload (must set overload_kill_enable=>true in opts)
diff --git a/lib/kernel/src/logger_server.erl b/lib/kernel/src/logger_server.erl
index f123eec8dd..722246e82c 100644
--- a/lib/kernel/src/logger_server.erl
+++ b/lib/kernel/src/logger_server.erl
@@ -154,6 +154,8 @@ init([]) ->
process_flag(trap_exit, true),
put(?LOGGER_SERVER_TAG,true),
Tid = logger_config:new(?LOGGER_TABLE),
+ %% Store initial proxy config. logger_proxy reads config from here at startup.
+ logger_config:create(Tid,proxy,logger_proxy:get_default_config()),
PrimaryConfig = maps:merge(default_config(primary),
#{handlers=>[simple]}),
logger_config:create(Tid,primary,PrimaryConfig),
@@ -220,6 +222,24 @@ handle_call({add_filter,Id,Filter}, _From,#state{tid=Tid}=State) ->
handle_call({remove_filter,Id,FilterId}, _From, #state{tid=Tid}=State) ->
Reply = do_remove_filter(Tid,Id,FilterId),
{reply,Reply,State};
+handle_call({change_config,SetOrUpd,proxy,Config0},_From,#state{tid=Tid}=State) ->
+ Default =
+ case SetOrUpd of
+ set ->
+ logger_proxy:get_default_config();
+ update ->
+ {ok,OldConfig} = logger_config:get(Tid,proxy),
+ OldConfig
+ end,
+ Config = maps:merge(Default,Config0),
+ Reply =
+ case logger_olp:set_opts(logger_proxy,Config) of
+ ok ->
+ logger_config:set(Tid,proxy,Config);
+ Error ->
+ Error
+ end,
+ {reply,Reply,State};
handle_call({change_config,SetOrUpd,primary,Config0}, _From,
#state{tid=Tid}=State) ->
{ok,#{handlers:=Handlers}=OldConfig} = logger_config:get(Tid,primary),
@@ -413,11 +433,13 @@ default_config(Id,Module) ->
sanity_check(Owner,Key,Value) ->
sanity_check_1(Owner,[{Key,Value}]).
-sanity_check(HandlerId,Config) when is_map(Config) ->
- sanity_check_1(HandlerId,maps:to_list(Config));
+sanity_check(Owner,Config) when is_map(Config) ->
+ sanity_check_1(Owner,maps:to_list(Config));
sanity_check(_,Config) ->
{error,{invalid_config,Config}}.
+sanity_check_1(proxy,_Config) ->
+ ok; % Details are checked by logger_olp:set_opts/2
sanity_check_1(Owner,Config) when is_list(Config) ->
try
Type = get_type(Owner),