diff --git a/.travis.yml b/.travis.yml index 7d9265c..b06e34b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ otp_release: - R16B01 - R16B - R15B02 -script: "./rebar3 compile && ./rebar3 ct" +script: "./rebar3 update && ./rebar3 compile && ./rebar3 ct" branches: only: - master diff --git a/rebar.config b/rebar.config index 7f67a43..c20e0f2 100644 --- a/rebar.config +++ b/rebar.config @@ -1,7 +1,7 @@ %% -*- mode: Erlang; fill-column: 80; comment-column: 75; -*- %% Dependencies ================================================================ -{deps, []}. +{deps, [cf]}. {erl_first_files, ["ec_dictionary", "ec_vsn"]}. diff --git a/rebar.lock b/rebar.lock index 57afcca..477758c 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1 +1 @@ -[]. +[{<<"cf">>,{pkg,<<"cf">>,<<"0.1.2">>},0}]. diff --git a/src/ec_cmd_log.erl b/src/ec_cmd_log.erl index 66ee40c..3cd75ae 100644 --- a/src/ec_cmd_log.erl +++ b/src/ec_cmd_log.erl @@ -24,6 +24,7 @@ -export([new/1, new/2, + new/3, log/4, should/2, debug/2, @@ -40,17 +41,18 @@ -include("ec_cmd_log.hrl"). --define(RED, 31). --define(GREEN, 32). --define(YELLOW, 33). --define(BLUE, 34). --define(MAGENTA, 35). --define(CYAN, 36). +-define(RED, $r). +-define(GREEN, $g). +-define(YELLOW, $y). +-define(BLUE, $b). +-define(MAGENTA, $m). +-define(CYAN, $c). -define(PREFIX, "===> "). -record(state_t, {log_level=0 :: int_log_level(), caller=api :: caller(), + intensity=low :: low | high, term_cap=full :: full | dumb }). %%============================================================================ @@ -71,9 +73,11 @@ -type atom_log_level() :: error | warn | info | debug. +-type intensity() :: low | high. + -type log_fun() :: fun(() -> iolist()). --type color() :: 31..36. +-type color() :: char(). -opaque t() :: #state_t{}. @@ -86,9 +90,17 @@ new(LogLevel) -> new(LogLevel, api). -spec new(log_level(), caller()) -> t(). -new(LogLevel, Caller) when LogLevel >= 0, LogLevel =< 3 -> - #state_t{log_level=LogLevel, caller=Caller, term_cap=query_term_env()}; -new(AtomLogLevel, Caller) +new(LogLevel, Caller) -> + new(LogLevel, Caller, high). + + +-spec new(log_level(), caller(), intensity()) -> t(). +new(LogLevel, Caller, Intensity) when (Intensity =:= low orelse + Intensity =:= high), + LogLevel >= 0, LogLevel =< 3 -> + #state_t{log_level=LogLevel, caller=Caller, term_cap=query_term_env(), + intensity=Intensity}; +new(AtomLogLevel, Caller, Intensity) when AtomLogLevel =:= error; AtomLogLevel =:= warn; AtomLogLevel =:= info; @@ -99,7 +111,8 @@ new(AtomLogLevel, Caller) info -> 2; debug -> 3 end, - new(LogLevel, Caller). + new(LogLevel, Caller, Intensity). + %% @doc log at the debug level given the current log state with a string or %% function that returns a string @@ -218,10 +231,25 @@ format(Log) -> <<")">>]. -spec colorize(t(), color(), boolean(), string()) -> string(). -colorize(#state_t{caller=command_line, term_cap=full}, Color, false, Msg) when is_integer(Color) -> - lists:flatten(io_lib:format("\033[~B;~Bm~s~s\033[0m", [0, Color, ?PREFIX, Msg])); -colorize(#state_t{caller=command_line, term_cap=dumb}, Color, _Bold, Msg) when is_integer(Color) -> - lists:flatten(io_lib:format("~s~s", [?PREFIX, Msg])); + +-define(VALID_COLOR(C), + C =:= $r orelse C =:= $g orelse C =:= $y orelse + C =:= $b orelse C =:= $m orelse C =:= $c orelse + C =:= $R orelse C =:= $G orelse C =:= $Y orelse + C =:= $B orelse C =:= $M orelse C =:= $C). + +%% We're sneaky we can substract 32 to get the uppercase character +colorize(State, Color, true, Msg) when ?VALID_COLOR(Color) -> + colorize(State, Color - 32, fase, Msg); +colorize(#state_t{caller=command_line, term_cap=full, intensity = high}, + Color, false, Msg) when ?VALID_COLOR(Color) -> + lists:flatten(cf:format("~!" ++ [Color] ++"~s~s", [?PREFIX, Msg])); +colorize(#state_t{caller=command_line, term_cap=full, intensity = low}, + Color, false, Msg) when ?VALID_COLOR(Color) -> + lists:flatten(cf:format("~!" ++ [Color] ++"~s~!!~s", [?PREFIX, Msg])); +colorize(#state_t{caller=command_line, term_cap=dumb}, Color, _Bold, Msg) + when ?VALID_COLOR(Color) -> + lists:flatten(cf:format("~s~s", [?PREFIX, Msg])); colorize(_LogState, _Color, _Bold, Msg) -> Msg. diff --git a/src/erlware_commons.app.src b/src/erlware_commons.app.src index c4ad6a7..899d930 100644 --- a/src/erlware_commons.app.src +++ b/src/erlware_commons.app.src @@ -1,6 +1,6 @@ {application,erlware_commons, [{description,"Additional standard library for Erlang"}, - {vsn,"0.16.0"}, + {vsn,"0.16.1"}, {modules,[]}, {registered,[]}, {applications,[kernel,stdlib]},