summaryrefslogtreecommitdiff
path: root/src/rebar_log.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_log.erl')
-rw-r--r--src/rebar_log.erl46
1 files changed, 41 insertions, 5 deletions
diff --git a/src/rebar_log.erl b/src/rebar_log.erl
index 06cfa9c..23ae81e 100644
--- a/src/rebar_log.erl
+++ b/src/rebar_log.erl
@@ -28,20 +28,43 @@
-export([init/2,
set_level/1,
+ get_level/0,
error_level/0,
default_level/0,
+ intensity/0,
log/3,
- is_verbose/1]).
+ is_verbose/1,
+ valid_level/1]).
-define(ERROR_LEVEL, 0).
-define(WARN_LEVEL, 1).
-define(INFO_LEVEL, 2).
-define(DEBUG_LEVEL, 3).
+-define(DFLT_INTENSITY, high).
%% ===================================================================
%% Public API
%% ===================================================================
+%% @doc Returns the color intensity, we first check the application envorinment
+%% if that is not set we check the environment variable REBAR_COLOR.
+intensity() ->
+ case application:get_env(rebar, color_intensity) of
+ undefined ->
+ R = case os:getenv("REBAR_COLOR") of
+ "high" ->
+ high;
+ "low" ->
+ low;
+ _ ->
+ ?DFLT_INTENSITY
+ end,
+ application:set_env(rebar, color_intensity, R),
+ R;
+ {ok, Mode} ->
+ Mode
+ end.
+
init(Caller, Verbosity) ->
Level = case valid_level(Verbosity) of
?ERROR_LEVEL -> error;
@@ -49,12 +72,25 @@ init(Caller, Verbosity) ->
?INFO_LEVEL -> info;
?DEBUG_LEVEL -> debug
end,
- Log = ec_cmd_log:new(Level, Caller),
+ Intensity = intensity(),
+ Log = ec_cmd_log:new(Level, Caller, Intensity),
+ set_level(valid_level(Verbosity)),
application:set_env(rebar, log, Log).
set_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) ->
+ {ok, LogState} = application:get_env(rebar, log),
+ ec_cmd_log:Level(LogState, lists:flatten(cf:format("~!^~s~n", [Str])), Args);
log(Level, Str, Args) ->
{ok, LogState} = application:get_env(rebar, log),
ec_cmd_log:Level(LogState, Str++"~n", Args).
@@ -65,9 +101,9 @@ default_level() -> ?INFO_LEVEL.
is_verbose(State) ->
rebar_state:get(State, is_verbose, false).
+valid_level(Level) ->
+ erlang:max(?ERROR_LEVEL, erlang:min(Level, ?DEBUG_LEVEL)).
+
%% ===================================================================
%% Internal functions
%% ===================================================================
-
-valid_level(Level) ->
- erlang:max(?ERROR_LEVEL, erlang:min(Level, ?DEBUG_LEVEL)).