Write ERROR messages to standard_error device

This commit is contained in:
Tuncer Ayaz 2013-12-03 19:59:28 +01:00
parent 6de94e8a16
commit f39309a660
2 changed files with 7 additions and 3 deletions

View file

@ -9,6 +9,6 @@
-define(DEBUG(Str, Args), rebar_log:log(debug, Str, Args)). -define(DEBUG(Str, Args), rebar_log:log(debug, Str, Args)).
-define(INFO(Str, Args), rebar_log:log(info, Str, Args)). -define(INFO(Str, Args), rebar_log:log(info, Str, Args)).
-define(WARN(Str, Args), rebar_log:log(warn, Str, Args)). -define(WARN(Str, Args), rebar_log:log(warn, Str, Args)).
-define(ERROR(Str, Args), rebar_log:log(error, Str, Args)). -define(ERROR(Str, Args), rebar_log:log(standard_error, error, Str, Args)).
-define(FMT(Str, Args), lists:flatten(io_lib:format(Str, Args))). -define(FMT(Str, Args), lists:flatten(io_lib:format(Str, Args))).

View file

@ -30,7 +30,8 @@
set_level/1, set_level/1,
error_level/0, error_level/0,
default_level/0, default_level/0,
log/3]). log/3,
log/4]).
-define(ERROR_LEVEL, 0). -define(ERROR_LEVEL, 0).
-define(WARN_LEVEL, 1). -define(WARN_LEVEL, 1).
@ -54,10 +55,13 @@ set_level(Level) ->
ok = application:set_env(rebar, log_level, Level). ok = application:set_env(rebar, log_level, Level).
log(Level, Str, Args) -> log(Level, Str, Args) ->
log(standard_io, Level, Str, Args).
log(Device, Level, Str, Args) ->
{ok, LogLevel} = application:get_env(rebar, log_level), {ok, LogLevel} = application:get_env(rebar, log_level),
case should_log(LogLevel, Level) of case should_log(LogLevel, Level) of
true -> true ->
io:format(log_prefix(Level) ++ Str, Args); io:format(Device, log_prefix(Level) ++ Str, Args);
false -> false ->
ok ok
end. end.