Browse Source

pass loglevel used in rebar3 to relx

pull/1110/head
Tristan Sloughter 9 years ago
parent
commit
c67ac9292c
2 changed files with 20 additions and 6 deletions
  1. +15
    -4
      src/rebar_log.erl
  2. +5
    -2
      src/rebar_relx.erl

+ 15
- 4
src/rebar_log.erl View File

@ -28,11 +28,13 @@
-export([init/2, -export([init/2,
set_level/1, set_level/1,
get_level/0,
error_level/0, error_level/0,
default_level/0, default_level/0,
intensity/0, intensity/0,
log/3, log/3,
is_verbose/1]).
is_verbose/1,
valid_level/1]).
-define(ERROR_LEVEL, 0). -define(ERROR_LEVEL, 0).
-define(WARN_LEVEL, 1). -define(WARN_LEVEL, 1).
@ -72,11 +74,20 @@ init(Caller, Verbosity) ->
end, end,
Intensity = intensity(), Intensity = intensity(),
Log = ec_cmd_log:new(Level, Caller, Intensity), Log = ec_cmd_log:new(Level, Caller, Intensity),
set_level(valid_level(Verbosity)),
application:set_env(rebar, log, Log). application:set_env(rebar, log, Log).
set_level(Level) -> set_level(Level) ->
ok = application:set_env(rebar, log_level, Level). ok = application:set_env(rebar, log_level, Level).
get_level() ->
case application:get_env(rebar, log_level) of
undefined ->
default_level();
{ok, Level} ->
Level
end.
log(Level = error, Str, Args) -> log(Level = error, Str, Args) ->
{ok, LogState} = application:get_env(rebar, log), {ok, LogState} = application:get_env(rebar, log),
ec_cmd_log:Level(LogState, lists:flatten(cf:format("~!^~s~n", [Str])), Args); ec_cmd_log:Level(LogState, lists:flatten(cf:format("~!^~s~n", [Str])), Args);
@ -90,9 +101,9 @@ default_level() -> ?INFO_LEVEL.
is_verbose(State) -> is_verbose(State) ->
rebar_state:get(State, is_verbose, false). rebar_state:get(State, is_verbose, false).
valid_level(Level) ->
erlang:max(?ERROR_LEVEL, erlang:min(Level, ?DEBUG_LEVEL)).
%% =================================================================== %% ===================================================================
%% Internal functions %% Internal functions
%% =================================================================== %% ===================================================================
valid_level(Level) ->
erlang:max(?ERROR_LEVEL, erlang:min(Level, ?DEBUG_LEVEL)).

+ 5
- 2
src/rebar_relx.erl View File

@ -16,6 +16,7 @@
do(Module, Command, Provider, State) -> do(Module, Command, Provider, State) ->
%% We set the color mode for relx as a application env %% We set the color mode for relx as a application env
application:set_env(relx, color_intensity, rebar_log:intensity()), application:set_env(relx, color_intensity, rebar_log:intensity()),
LogLevel = rebar_log:get_level(),
Options = rebar_state:command_args(State), Options = rebar_state:command_args(State),
DepsDir = rebar_dir:deps_dir(State), DepsDir = rebar_dir:deps_dir(State),
ProjectAppDirs = lists:delete(".", ?DEFAULT_PROJECT_APP_DIRS), ProjectAppDirs = lists:delete(".", ?DEFAULT_PROJECT_APP_DIRS),
@ -30,12 +31,14 @@ do(Module, Command, Provider, State) ->
case rebar_state:get(State, relx, []) of case rebar_state:get(State, relx, []) of
[] -> [] ->
relx:main([{lib_dirs, LibDirs} relx:main([{lib_dirs, LibDirs}
,{caller, api} | output_dir(OutputDir, Options)], AllOptions);
,{caller, api}
,{log_level, LogLevel} | output_dir(OutputDir, Options)], AllOptions);
Config -> Config ->
Config1 = merge_overlays(Config), Config1 = merge_overlays(Config),
relx:main([{lib_dirs, LibDirs} relx:main([{lib_dirs, LibDirs}
,{config, Config1} ,{config, Config1}
,{caller, api} | output_dir(OutputDir, Options)], AllOptions)
,{caller, api}
,{log_level, LogLevel} | output_dir(OutputDir, Options)], AllOptions)
end, end,
rebar_hooks:run_project_and_app_hooks(Cwd, post, Provider, Providers, State), rebar_hooks:run_project_and_app_hooks(Cwd, post, Provider, Providers, State),
{ok, State} {ok, State}

Loading…
Cancel
Save