diff options
author | Tristan Sloughter <[email protected]> | 2013-09-28 11:56:32 -0500 |
---|---|---|
committer | Tristan Sloughter <[email protected]> | 2013-09-28 16:26:00 -0500 |
commit | 3fc8e0408cd27e15fdfbd3711c6ab18140745c86 (patch) | |
tree | f18af1a207aa2964e49085081a6dcc4f06c2ac10 /src | |
parent | 8a60327694646893729cde1708be4f507beceae0 (diff) | |
download | relx-3fc8e0408cd27e15fdfbd3711c6ab18140745c86.tar.gz relx-3fc8e0408cd27e15fdfbd3711c6ab18140745c86.tar.bz2 relx-3fc8e0408cd27e15fdfbd3711c6ab18140745c86.zip |
warn, not error, on bad app during discovery provider
Diffstat (limited to 'src')
-rw-r--r-- | src/relx.erl | 4 | ||||
-rw-r--r-- | src/rlx_app_discovery.erl | 19 | ||||
-rw-r--r-- | src/rlx_cmd_args.erl | 4 | ||||
-rw-r--r-- | src/rlx_dscv_util.erl | 2 | ||||
-rw-r--r-- | src/rlx_log.erl | 33 | ||||
-rw-r--r-- | src/rlx_rel_discovery.erl | 2 |
6 files changed, 45 insertions, 19 deletions
diff --git a/src/relx.erl b/src/relx.erl index f6575a1..f6e156d 100644 --- a/src/relx.erl +++ b/src/relx.erl @@ -195,8 +195,8 @@ opt_spec_list() -> {default_libs, undefined, "default-libs", {boolean, true}, "Whether to use the default system added lib dirs (means you must add them all manually). Default is true"}, - {log_level, $V, "verbose", {integer, 1}, - "Verbosity level, maybe between 0 and 2"}, + {log_level, $V, "verbose", {integer, 2}, + "Verbosity level, maybe between 0 and 3"}, {override_app, $a, "override_app", string, "Provide an app name and a directory to override in the form <appname>:<app directory>"}, {config, $c, "config", {string, ""}, "The path to a config file"}, diff --git a/src/rlx_app_discovery.erl b/src/rlx_app_discovery.erl index 39f3921..cf0d1c6 100644 --- a/src/rlx_app_discovery.erl +++ b/src/rlx_app_discovery.erl @@ -39,8 +39,8 @@ do(State, LibDirs) -> rlx_log:info(rlx_state:log(State), fun() -> - ["Resolving OTP Applications from directories:\n", - [[rlx_util:indent(2), LibDir, "\n"] || LibDir <- LibDirs]] + ["Resolving OTP Applications from directories:\n", + string:join([[rlx_util:indent(2), LibDir] || LibDir <- LibDirs], "\n")] end), resolve_app_metadata(State, LibDirs). @@ -62,6 +62,9 @@ resolve_app_metadata(State, LibDirs) -> case Err of {error, _} -> true; + {warning, W} -> + rlx_log:warn(rlx_state:log(State), format_detail(W)), + false; _ -> false end] of @@ -79,6 +82,8 @@ resolve_app_metadata(State, LibDirs) -> ?RLX_ERROR(Errors) end. +app_name({warning, _}) -> + undefined; app_name({error, _}) -> undefined; app_name({ok, AppMeta}) -> @@ -103,7 +108,7 @@ resolve_override(AppName, FileName0) -> end. -spec format_detail(ErrorDetail::term()) -> iolist(). -format_detail({error, {missing_beam_file, Module, BeamFile}}) -> +format_detail({missing_beam_file, Module, BeamFile}) -> io_lib:format("Missing beam file ~p ~p", [Module, BeamFile]); format_detail({error, {invalid_override, AppName, FileName}}) -> io_lib:format("Override {~p, ~p} is not a valid OTP App. Perhaps you forgot to build it?", @@ -161,9 +166,9 @@ gather_application_info(EbinDir, File) -> {ok, [{application, AppName, AppDetail}]} -> validate_application_info(EbinDir, File, AppName, AppDetail); {error, Reason} -> - {error, {unable_to_load_app, AppDir, Reason}}; + {warning, {unable_to_load_app, AppDir, Reason}}; _ -> - {error, {invalid_app_file, File}} + {warning, {invalid_app_file, File}} end. -spec validate_application_info(file:name(), @@ -189,7 +194,7 @@ validate_application_info(EbinDir, AppFile, AppName, AppDetail) -> get_modules_list(AppFile, AppDetail) -> case proplists:get_value(modules, AppDetail) of undefined -> - {error, {invalid_app_file, AppFile}}; + {warning, {invalid_app_file, AppFile}}; ModulesList -> {ok, ModulesList} end. @@ -203,7 +208,7 @@ has_all_beams(EbinDir, [Module | ModuleList]) -> true -> has_all_beams(EbinDir, ModuleList); false -> - {error, {missing_beam_file, Module, BeamFile}} + {warning, {missing_beam_file, Module, BeamFile}} end; has_all_beams(_, []) -> ok. diff --git a/src/rlx_cmd_args.erl b/src/rlx_cmd_args.erl index 621b626..57c9a57 100644 --- a/src/rlx_cmd_args.erl +++ b/src/rlx_cmd_args.erl @@ -80,7 +80,7 @@ format_error({not_directory, Dir}) -> io_lib:format("Library directory does not exist: ~s", [Dir]); format_error({invalid_log_level, LogLevel}) -> io_lib:format("Invalid log level specified -V ~p, log level must be in the" - " range 0..2", [LogLevel]); + " range 0..3", [LogLevel]); format_error({invalid_target, Target}) -> io_lib:format("Invalid action specified: ~s", [Target]). @@ -136,7 +136,7 @@ validate_config(Config) -> create_log(Opts, Acc) -> LogLevel = proplists:get_value(log_level, Opts, 0), if - LogLevel >= 0, LogLevel =< 2 -> + LogLevel >= 0, LogLevel =< 3 -> create_goals(Opts, [{log, rlx_log:new(LogLevel, command_line)} | Acc]); true -> ?RLX_ERROR({invalid_log_level, LogLevel}) diff --git a/src/rlx_dscv_util.erl b/src/rlx_dscv_util.erl index 779534c..52bbd07 100644 --- a/src/rlx_dscv_util.erl +++ b/src/rlx_dscv_util.erl @@ -97,6 +97,8 @@ discover_dir(ProcessDir, File, file) -> [{ok, Result}]; {noresult, _} -> []; + Warn = {warning, _} -> + [Warn]; Err = {error, _} -> [Err] end; diff --git a/src/rlx_log.erl b/src/rlx_log.erl index 608c0af..64997a2 100644 --- a/src/rlx_log.erl +++ b/src/rlx_log.erl @@ -32,6 +32,8 @@ info/3, error/2, error/3, + warn/2, + warn/3, log_level/1, atom_log_level/1, format/1]). @@ -63,11 +65,9 @@ -type log_level() :: int_log_level() | atom_log_level(). --type int_log_level() :: 0..2. +-type int_log_level() :: 0..3. -%% Why no warn? because for our purposes there is no difference between error -%% and warn --type atom_log_level() :: error | info | debug. +-type atom_log_level() :: error | warn | info | debug. -type log_fun() :: fun(() -> iolist()). @@ -83,16 +83,18 @@ new(LogLevel) -> new(LogLevel, api). -new(LogLevel, Caller) when LogLevel >= 0, LogLevel =< 2 -> +new(LogLevel, Caller) when LogLevel >= 0, LogLevel =< 3 -> #state_t{mod=?MODULE, log_level=LogLevel, caller=Caller}; new(AtomLogLevel, Caller) when AtomLogLevel =:= error; + AtomLogLevel =:= warn; AtomLogLevel =:= info; AtomLogLevel =:= debug -> LogLevel = case AtomLogLevel of error -> 0; - info -> 1; - debug -> 2 + warn -> 1; + info -> 2; + debug -> 3 end, new(LogLevel, Caller). @@ -142,6 +144,21 @@ error(LogState, String) -> error(LogState, FormatString, Args) -> log(LogState, ?RLX_ERROR, colorize(LogState, ?GREEN, false, FormatString), Args). +%% @doc log at the warn level given the current log state with a string or +%% format string that returns a function +-spec warn(t(), string() | log_fun()) -> ok. +warn(LogState, Fun) + when erlang:is_function(Fun) -> + log(LogState, ?RLX_WARN, fun() -> colorize(LogState, ?MAGENTA, false, Fun()) end); +warn(LogState, String) -> + warn(LogState, "~s~n", [String]). + +%% @doc log at the warn level given the current log state with a format string +%% and argements @see io:format/2 +-spec warn(t(), string(), [any()]) -> ok. +warn(LogState, FormatString, Args) -> + log(LogState, ?RLX_WARN, colorize(LogState, ?MAGENTA, false, FormatString), Args). + %% @doc Execute the fun passed in if log level is as expected. -spec log(t(), int_log_level(), log_fun()) -> ok. log(#state_t{mod=?MODULE, log_level=DetailLogLevel}, LogLevel, Fun) @@ -178,6 +195,8 @@ log_level(#state_t{mod=?MODULE, log_level=DetailLogLevel}) -> -spec atom_log_level(t()) -> atom_log_level(). atom_log_level(#state_t{mod=?MODULE, log_level=?RLX_ERROR}) -> error; +atom_log_level(#state_t{mod=?MODULE, log_level=?RLX_WARN}) -> + warn; atom_log_level(#state_t{mod=?MODULE, log_level=?RLX_INFO}) -> info; atom_log_level(#state_t{mod=?MODULE, log_level=?RLX_DEBUG}) -> diff --git a/src/rlx_rel_discovery.erl b/src/rlx_rel_discovery.erl index 1616f52..ee9d941 100644 --- a/src/rlx_rel_discovery.erl +++ b/src/rlx_rel_discovery.erl @@ -41,7 +41,7 @@ do(State, LibDirs, AppMeta) -> rlx_log:info(rlx_state:log(State), fun() -> ["Resolving available OTP Releases from directories:\n", - [[rlx_util:indent(2), LibDir, "\n"] || LibDir <- LibDirs]] + string:join([[rlx_util:indent(2), LibDir] || LibDir <- LibDirs], "\n")] end), resolve_rel_metadata(State, LibDirs, AppMeta). |