25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Add 'ejabberdctl foreground-quiet'

This starts ejabberd without detaching process but setups
console logging to display only critical messages.
This commit is contained in:
Paweł Chmielowski 2021-01-27 09:24:05 +01:00
parent b977320091
commit 3516d2053c
2 changed files with 24 additions and 3 deletions

View File

@ -277,6 +277,10 @@ case $1 in
check_start check_start
exec_erl "$ERLANG_NODE" $EJABBERD_OPTS -noinput exec_erl "$ERLANG_NODE" $EJABBERD_OPTS -noinput
;; ;;
foreground-quiet)
check_start
exec_erl "$ERLANG_NODE" $EJABBERD_OPTS -noinput -ejabberd quiet true
;;
live) live)
livewarning livewarning
check_start check_start

View File

@ -76,6 +76,12 @@ convert_loglevel(3) -> warning;
convert_loglevel(4) -> info; convert_loglevel(4) -> info;
convert_loglevel(5) -> debug. convert_loglevel(5) -> debug.
quiet_mode() ->
case application:get_env(ejabberd, quiet) of
{ok, true} -> true;
_ -> false
end.
-spec get_integer_env(atom(), T) -> T. -spec get_integer_env(atom(), T) -> T.
get_integer_env(Name, Default) -> get_integer_env(Name, Default) ->
case application:get_env(ejabberd, Name) of case application:get_env(ejabberd, Name) of
@ -150,9 +156,13 @@ do_start(Level) ->
end, end,
LogRotateCount = get_integer_env(log_rotate_count, 1), LogRotateCount = get_integer_env(log_rotate_count, 1),
LogRateLimit = get_integer_env(log_rate_limit, 100), LogRateLimit = get_integer_env(log_rate_limit, 100),
ConsoleLevel0 = case quiet_mode() of
true -> critical;
_ -> Level
end,
ConsoleLevel = case get_lager_version() >= "3.6.0" of ConsoleLevel = case get_lager_version() >= "3.6.0" of
true -> [{level, Level}]; true -> [{level, ConsoleLevel0}];
false -> Level false -> ConsoleLevel0
end, end,
application:set_env(lager, error_logger_hwm, LogRateLimit), application:set_env(lager, error_logger_hwm, LogRateLimit),
application:set_env( application:set_env(
@ -212,10 +222,11 @@ set(Level) when ?is_loglevel(Level) ->
ok; ok;
_ -> _ ->
ConsoleLog = get_log_path(), ConsoleLog = get_log_path(),
QuietMode = quiet_mode(),
lists:foreach( lists:foreach(
fun({lager_file_backend, File} = H) when File == ConsoleLog -> fun({lager_file_backend, File} = H) when File == ConsoleLog ->
lager:set_loglevel(H, Level); lager:set_loglevel(H, Level);
(lager_console_backend = H) -> (lager_console_backend = H) when not QuietMode ->
lager:set_loglevel(H, Level); lager:set_loglevel(H, Level);
(elixir_logger_backend = H) -> (elixir_logger_backend = H) ->
lager:set_loglevel(H, Level); lager:set_loglevel(H, Level);
@ -278,6 +289,12 @@ start(Level) ->
try try
ok = logger:set_primary_config(level, Level), ok = logger:set_primary_config(level, Level),
ok = logger:update_formatter_config(default, ConsoleFmtConfig), ok = logger:update_formatter_config(default, ConsoleFmtConfig),
case quiet_mode() of
true ->
ok = logger:set_handler_config(default, level, critical);
_ ->
ok
end,
case logger:add_primary_filter(progress_report, case logger:add_primary_filter(progress_report,
{fun ?MODULE:progress_filter/2, stop}) of {fun ?MODULE:progress_filter/2, stop}) of
ok -> ok; ok -> ok;