diff --git a/src/ejabberd_admin.erl b/src/ejabberd_admin.erl index 49042f4d5..ab758fb36 100644 --- a/src/ejabberd_admin.erl +++ b/src/ejabberd_admin.erl @@ -28,7 +28,7 @@ -export([start/0, stop/0, %% Server - status/0, reopen_log/0, + status/0, reopen_log/0, rotate_log/0, set_loglevel/1, stop_kindly/2, send_service_message_all_mucs/2, registered_vhosts/0, @@ -88,6 +88,10 @@ commands() -> desc = "Reopen the log files", module = ?MODULE, function = reopen_log, args = [], result = {res, rescode}}, + #ejabberd_commands{name = rotate_log, tags = [logs, server], + desc = "Rotate the log files", + module = ?MODULE, function = rotate_log, + args = [], result = {res, rescode}}, #ejabberd_commands{name = stop_kindly, tags = [server], desc = "Inform users and rooms, wait, and stop the server", longdesc = "Provide the delay in seconds, and the " @@ -276,6 +280,9 @@ reopen_log() -> ejabberd_hooks:run(reopen_log_hook, []), ejabberd_logger:reopen_log(). +rotate_log() -> + ejabberd_hooks:run(rotate_log_hook, []), + ejabberd_logger:rotate_log(). set_loglevel(LogLevel) -> {module, Module} = ejabberd_logger:set(LogLevel), diff --git a/src/ejabberd_logger.erl b/src/ejabberd_logger.erl index 6f2457831..3545abe84 100644 --- a/src/ejabberd_logger.erl +++ b/src/ejabberd_logger.erl @@ -27,7 +27,7 @@ -behaviour(ejabberd_config). %% API --export([start/0, reopen_log/0, get/0, set/1, get_log_path/0, opt_type/1]). +-export([start/0, reopen_log/0, rotate_log/0, get/0, set/1, get_log_path/0, opt_type/1]). -include("ejabberd.hrl"). @@ -36,6 +36,7 @@ -spec start() -> ok. -spec get_log_path() -> string(). -spec reopen_log() -> ok. +-spec rotate_log() -> ok. -spec get() -> {loglevel(), atom(), string()}. -spec set(loglevel() | {loglevel(), list()}) -> {module, module()}. @@ -128,6 +129,10 @@ start() -> ok. reopen_log() -> + %% Lager detects external log rotation automatically. + ok. + +rotate_log() -> lager_crash_log ! rotate, lists:foreach( fun({lager_file_backend, File}) -> @@ -191,6 +196,10 @@ reopen_log() -> p1_logger_h:reopen_log(), reopen_sasl_log(). +rotate_log() -> + %% Not implemented. + ok. + get() -> p1_loglevel:get().