summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDmitri Vereshchagin <dmitri.vereshchagin@gmail.com>2019-08-28 07:40:56 +0300
committerDmitri Vereshchagin <dmitri.vereshchagin@gmail.com>2019-08-28 07:40:56 +0300
commit0392742ceb52f5b8eefdd8138387b2c8f2e9fd48 (patch)
tree100fbe31bee9bfc8fab00f518a0d59ecd0cb5270 /src
parent542b93a8526873dd3bbc0440aad3e7d3093ac4d8 (diff)
Disable the default logger handler in shell if required
To avoid a conflict the Kernel's default handler have to be disabled before the new default handler is added {kernel, [{logger, [{handler, default, undefined} ]} ]}, {my_app, [{logger, [{handler, default, my_handler, #{}} ]} ]} To support this behavior in shell it's necessary to process the handler-default-undefined tuple. It's not clear what to do with the simple handler (logger_simple_h) however. It's added at the start and removed if a default handler was added. Should it be added in reread_logger_config/1 if there's no default handler?
Diffstat (limited to 'src')
-rw-r--r--src/rebar_utils.erl21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 5c7da92..7b267e3 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -502,15 +502,26 @@ reread_logger_config() ->
Primary = #{level => LogLvlPrimary,
filter_default => FilterDefault,
filters => Filters},
- %% Load the correct handlers based on their individual config.
- [case Id of
- default -> logger:update_handler_config(Id, Cfg);
- _ -> logger:add_handler(Id, Mod, Cfg)
- end || {handler, Id, Mod, Cfg} <- LogCfg],
+ lists:foreach(fun maybe_reset_logger_handler/1, LogCfg),
logger:set_primary_config(Primary),
ok
end.
+%% @private add or update handlers based on their individual config,
+%% also remove default handler if needed.
+maybe_reset_logger_handler({handler, Id, Mod, Cfg}) ->
+ case logger:add_handler(Id, Mod, Cfg) of
+ {error, {already_exist, Id}} ->
+ logger:update_handler_config(Id, Cfg);
+ _ ->
+ ok
+ end;
+maybe_reset_logger_handler({handler, default, undefined}) ->
+ _ = logger:remove_handler(default),
+ ok;
+maybe_reset_logger_handler(_) ->
+ ok.
+
%% @doc Given env. variable `FOO' we want to expand all references to
%% it in `InStr'. References can have two forms: `$FOO' and `${FOO}'