diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2019-09-01 18:15:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-01 18:15:16 -0400 |
commit | e2ac32175806a80a3a92f1e5f554ee7688259350 (patch) | |
tree | 76100b930badb46b0b3ec84a301812842cd56d57 | |
parent | c031b0f24ef7289438817da6e6c244cc85df44ad (diff) | |
parent | 0392742ceb52f5b8eefdd8138387b2c8f2e9fd48 (diff) |
Merge pull request #2149 from dmitrivereshchagin/fix-logger-reset
Disable the default logger handler in shell if required
-rw-r--r-- | src/rebar_utils.erl | 21 |
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}' |