mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
add ability to rotate logs on given date condition
This commit is contained in:
parent
273631c242
commit
9265720f92
@ -6058,12 +6058,20 @@ The exact value is controlled by \term{log\_rotate\_size} option.
|
|||||||
The syntax is:
|
The syntax is:
|
||||||
\begin{description}
|
\begin{description}
|
||||||
\titem{log\_rotate\_size: N} Where N is the maximum size of a log file in bytes.
|
\titem{log\_rotate\_size: N} Where N is the maximum size of a log file in bytes.
|
||||||
The default value is 104857600 (10Mb).
|
The default value is 10485760 (10Mb).
|
||||||
|
\end{description}
|
||||||
|
|
||||||
|
\ejabberd{} can also rotates the log files at given date interval.
|
||||||
|
The exact value is controlled by \term{log\_rotate\_date} option.
|
||||||
|
The syntax is:
|
||||||
|
\begin{description}
|
||||||
|
\titem{log\_rotate\_date: D} Where D is a string with syntax is taken from the syntax newsyslog uses in newsyslog.conf.
|
||||||
|
The default value is \term{""} (no rotation triggered by date).
|
||||||
\end{description}
|
\end{description}
|
||||||
|
|
||||||
However, you can rotate the log files manually.
|
However, you can rotate the log files manually.
|
||||||
For doing this, set \term{log\_rotate\_size} option to some absurdly high value, then,
|
For doing this, set \term{log\_rotate\_size} option to 0 and \term{log\_rotate\_date}
|
||||||
when you need to rotate the files, rename and then reopen them.
|
to empty list, then, when you need to rotate the files, rename and then reopen them.
|
||||||
The ejabberdctl command \term{reopen-log}
|
The ejabberdctl command \term{reopen-log}
|
||||||
(please refer to section \ref{ectl-commands})
|
(please refer to section \ref{ectl-commands})
|
||||||
reopens the log files,
|
reopens the log files,
|
||||||
|
@ -24,8 +24,8 @@
|
|||||||
### > Art thou not Romeo,
|
### > Art thou not Romeo,
|
||||||
### and a Montague?
|
### and a Montague?
|
||||||
|
|
||||||
### =========
|
### =======
|
||||||
### DEBUGGING
|
### LOGGING
|
||||||
|
|
||||||
##
|
##
|
||||||
## loglevel: Verbosity of log files generated by ejabberd.
|
## loglevel: Verbosity of log files generated by ejabberd.
|
||||||
@ -38,6 +38,32 @@
|
|||||||
##
|
##
|
||||||
loglevel: 4
|
loglevel: 4
|
||||||
|
|
||||||
|
##
|
||||||
|
## rotation: Describe how to rotate logs. Either size and/or date can trigger
|
||||||
|
## log rotation. Setting count to N keeps N rotated logs. Setting count to 0
|
||||||
|
## does not disable rotation, it instead rotates the file and keeps no previous
|
||||||
|
## versions around. Setting size to X rotate log when it reaches X bytes.
|
||||||
|
## To disable rotation set the size to 0 and the date to ""
|
||||||
|
## Size syntax is taken from the syntax newsyslog uses in newsyslog.conf.
|
||||||
|
## Some examples:
|
||||||
|
## $D0 rotate every night at midnight
|
||||||
|
## $D23 rotate every day at 23:00 hr
|
||||||
|
## $W0D23 rotate every week on Sunday at 23:00 hr
|
||||||
|
## $W5D16 rotate every week on Friday at 16:00 hr
|
||||||
|
## $M1D0 rotate on the first day of every month at midnight
|
||||||
|
## $M5D6 rotate on every 5th day of the month at 6:00 hr
|
||||||
|
##
|
||||||
|
log_rotate_size: 10485760
|
||||||
|
log_rotate_date: ""
|
||||||
|
log_rotate_count: 1
|
||||||
|
|
||||||
|
##
|
||||||
|
## overload protection: If you want to limit the number of messages per second
|
||||||
|
## allowed from error_logger, which is a good idea if you want to weather a flood
|
||||||
|
## of messages when system is overloaded, you can set a limit.
|
||||||
|
## 100 is ejabberd's default.
|
||||||
|
log_rate_limit: 100
|
||||||
|
|
||||||
##
|
##
|
||||||
## watchdog_admins: Only useful for developers: if an ejabberd process
|
## watchdog_admins: Only useful for developers: if an ejabberd process
|
||||||
## consumes a lot of memory, send live notifications to these XMPP
|
## consumes a lot of memory, send live notifications to these XMPP
|
||||||
|
@ -126,6 +126,24 @@ else
|
|||||||
NAME="-name"
|
NAME="-name"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# define ejabberd environment parameters
|
||||||
|
if [ "$EJABBERD_CONFIG_PATH" != "${EJABBERD_CONFIG_PATH/.yml/}" ] ; then
|
||||||
|
rate=$(grep log_rate_limit $EJABBERD_CONFIG_PATH | cut -d':' -f2 | sed 's/ *//')
|
||||||
|
rotate=$(grep log_rotate_size $EJABBERD_CONFIG_PATH | cut -d':' -f2 | sed 's/ *//')
|
||||||
|
count=$(grep log_rotate_count $EJABBERD_CONFIG_PATH | cut -d':' -f2 | sed 's/ *//')
|
||||||
|
date=$(grep log_rotate_date $EJABBERD_CONFIG_PATH | cut -d':' -f2 | sed 's/ *//')
|
||||||
|
else
|
||||||
|
rate=$(grep log_rate_limit $EJABBERD_CONFIG_PATH | cut -d',' -f2 | sed 's/ *//;s/}\.//')
|
||||||
|
rotate=$(grep log_rotate_size $EJABBERD_CONFIG_PATH | cut -d',' -f2 | sed 's/ *//;s/}\.//')
|
||||||
|
count=$(grep log_rotate_count $EJABBERD_CONFIG_PATH | cut -d',' -f2 | sed 's/ *//;s/}\.//')
|
||||||
|
date=$(grep log_rotate_date $EJABBERD_CONFIG_PATH | cut -d',' -f2 | sed 's/ *//;s/}\.//')
|
||||||
|
fi
|
||||||
|
[ -z "$rate" ] || EJABBERD_OPTS="log_rate_limit $rate"
|
||||||
|
[ -z "$rotate" ] || EJABBERD_OPTS="${EJABBERD_OPTS} log_rotate_size $rotate"
|
||||||
|
[ -z "$count" ] || EJABBERD_OPTS="${EJABBERD_OPTS} log_rotate_count $count"
|
||||||
|
[ -z "$date" ] || EJABBERD_OPTS="${EJABBERD_OPTS} log_rotate_date '$date'"
|
||||||
|
[ -z "$EJABBERD_OPTS" ] || EJABBERD_OPTS="-ejabberd ${EJABBERD_OPTS}"
|
||||||
|
|
||||||
# create the ejabberd home dir with the proper user if doesn't exist
|
# create the ejabberd home dir with the proper user if doesn't exist
|
||||||
# then change to that directory readable by INSTALLUSER to
|
# then change to that directory readable by INSTALLUSER to
|
||||||
# prevent "File operation error: eacces." messages
|
# prevent "File operation error: eacces." messages
|
||||||
|
@ -73,6 +73,18 @@ get_pos_integer_env(Name, Default) ->
|
|||||||
[Name, Junk, Default]),
|
[Name, Junk, Default]),
|
||||||
Default
|
Default
|
||||||
end.
|
end.
|
||||||
|
get_pos_string_env(Name, Default) ->
|
||||||
|
case application:get_env(ejabberd, Name) of
|
||||||
|
{ok, L} when is_list(L) ->
|
||||||
|
L;
|
||||||
|
undefined ->
|
||||||
|
Default;
|
||||||
|
{ok, Junk} ->
|
||||||
|
error_logger:error_msg("wrong value for ~s: ~p; "
|
||||||
|
"using ~p as a fallback~n",
|
||||||
|
[Name, Junk, Default]),
|
||||||
|
Default
|
||||||
|
end.
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
application:load(sasl),
|
application:load(sasl),
|
||||||
@ -82,6 +94,7 @@ start() ->
|
|||||||
Dir = filename:dirname(ConsoleLog),
|
Dir = filename:dirname(ConsoleLog),
|
||||||
ErrorLog = filename:join([Dir, "error.log"]),
|
ErrorLog = filename:join([Dir, "error.log"]),
|
||||||
CrashLog = filename:join([Dir, "crash.log"]),
|
CrashLog = filename:join([Dir, "crash.log"]),
|
||||||
|
LogRotateDate = get_pos_string_env(log_rotate_date, ""),
|
||||||
LogRotateSize = get_pos_integer_env(log_rotate_size, 10*1024*1024),
|
LogRotateSize = get_pos_integer_env(log_rotate_size, 10*1024*1024),
|
||||||
LogRotateCount = get_pos_integer_env(log_rotate_count, 1),
|
LogRotateCount = get_pos_integer_env(log_rotate_count, 1),
|
||||||
LogRateLimit = get_pos_integer_env(log_rate_limit, 100),
|
LogRateLimit = get_pos_integer_env(log_rate_limit, 100),
|
||||||
@ -89,11 +102,12 @@ start() ->
|
|||||||
application:set_env(
|
application:set_env(
|
||||||
lager, handlers,
|
lager, handlers,
|
||||||
[{lager_console_backend, info},
|
[{lager_console_backend, info},
|
||||||
{lager_file_backend, [{file, ConsoleLog}, {level, info},
|
{lager_file_backend, [{file, ConsoleLog}, {level, info}, {date, LogRotateDate},
|
||||||
{count, LogRotateCount}, {size, LogRotateSize}]},
|
{count, LogRotateCount}, {size, LogRotateSize}]},
|
||||||
{lager_file_backend, [{file, ErrorLog}, {level, error},
|
{lager_file_backend, [{file, ErrorLog}, {level, error}, {date, LogRotateDate},
|
||||||
{count, LogRotateCount}, {size, LogRotateSize}]}]),
|
{count, LogRotateCount}, {size, LogRotateSize}]}]),
|
||||||
application:set_env(lager, crash_log, CrashLog),
|
application:set_env(lager, crash_log, CrashLog),
|
||||||
|
application:set_env(lager, crash_log_date, LogRotateDate),
|
||||||
application:set_env(lager, crash_log_size, LogRotateSize),
|
application:set_env(lager, crash_log_size, LogRotateSize),
|
||||||
application:set_env(lager, crash_log_count, LogRotateCount),
|
application:set_env(lager, crash_log_count, LogRotateCount),
|
||||||
ejabberd:start_app(lager),
|
ejabberd:start_app(lager),
|
||||||
|
Loading…
Reference in New Issue
Block a user