From 536c2c944ca702e7e79a36ce001df62e0ee1a97a Mon Sep 17 00:00:00 2001 From: Richard Carlsson Date: Mon, 29 Jan 2024 22:45:53 +0100 Subject: [PATCH] Make log_level entry in rebar.app work again The log_level app setting had become ignored during refactorings of old. This makes it take effect again and syncs its standard setting with that of with rebar_log:default_level(). We add rebar_log:atom_to_level/1 to avoid exposing the level numbers used internally. --- apps/rebar/src/rebar.app.src.script | 2 +- apps/rebar/src/rebar3.erl | 7 ++++++- apps/rebar/src/rebar_log.erl | 10 ++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/apps/rebar/src/rebar.app.src.script b/apps/rebar/src/rebar.app.src.script index 6a3afbb18..35f68fa1c 100644 --- a/apps/rebar/src/rebar.app.src.script +++ b/apps/rebar/src/rebar.app.src.script @@ -36,7 +36,7 @@ ]}, {env, [ %% Default log level - {log_level, warn}, + {log_level, info}, {resources, [{git, rebar_git_resource}, {git_subdir, rebar_git_subdir_resource}, diff --git a/apps/rebar/src/rebar3.erl b/apps/rebar/src/rebar3.erl index c9b129a09..ea89a5374 100644 --- a/apps/rebar/src/rebar3.erl +++ b/apps/rebar/src/rebar3.erl @@ -306,7 +306,12 @@ log_level() -> Di when Di == false; Di == "" -> case os:getenv("DEBUG") of D when D == false; D == "" -> - rebar_log:default_level(); + try + {ok, L} = application:get_env(rebar, log_level), + rebar_log:atom_to_level(L) + catch + _:_ -> rebar_log:default_level() + end; _ -> rebar_log:debug_level() end; diff --git a/apps/rebar/src/rebar_log.erl b/apps/rebar/src/rebar_log.erl index 6a9857036..4942bf7fb 100644 --- a/apps/rebar/src/rebar_log.erl +++ b/apps/rebar/src/rebar_log.erl @@ -34,6 +34,7 @@ default_level/0, debug_level/0, diagnostic_level/0, + atom_to_level/1, intensity/0, log/3, is_verbose/1, @@ -143,6 +144,15 @@ is_verbose(State) -> valid_level(Level) -> erlang:max(?ERROR_LEVEL, erlang:min(Level, ?DIAGNOSTIC_LEVEL)). +atom_to_level(Level) -> + case Level of + error -> ?ERROR_LEVEL; + warn -> ?WARN_LEVEL; + info -> ?INFO_LEVEL; + debug -> ?DEBUG_LEVEL; + diagnostic -> ?DIAGNOSTIC_LEVEL + end. + %% =================================================================== %% Internal functions %% ===================================================================