]> granicus.if.org Git - ejabberd/commitdiff
add ability to rotate logs on given date condition
authorChristophe Romain <christophe.romain@process-one.net>
Wed, 2 Jul 2014 08:41:12 +0000 (10:41 +0200)
committerChristophe Romain <christophe.romain@process-one.net>
Wed, 2 Jul 2014 21:46:54 +0000 (23:46 +0200)
doc/guide.tex
ejabberd.yml.example
ejabberdctl.template
src/ejabberd_logger.erl

index 5240079650309d18c7562bf3ef55294f0215ac4f..ba7349864aa4c509c86f43fe9aae4da2d4331312 100644 (file)
@@ -6058,12 +6058,20 @@ The exact value is controlled by \term{log\_rotate\_size} option.
 The syntax is:
 \begin{description}
   \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}
 
 However, you can rotate the log files manually.
-For doing this, set \term{log\_rotate\_size} option to some absurdly high value, then,
-when you need to rotate the files, rename and then reopen them.
+For doing this, set \term{log\_rotate\_size} option to 0 and \term{log\_rotate\_date}
+to empty list, then, when you need to rotate the files, rename and then reopen them.
 The ejabberdctl command \term{reopen-log} 
 (please refer to section \ref{ectl-commands})
 reopens the log files,
index 1f55fe990bea64d20b6d79de52b893a0a60d31ea..8f16d1a4e0ebf1508823a0d12cab96251d47e41f 100644 (file)
@@ -24,8 +24,8 @@
 ###   > Art thou not Romeo,
 ###     and a Montague?
 
-###   =========
-###   DEBUGGING
+###   =======
+###   LOGGING
 
 ##
 ## loglevel: Verbosity of log files generated by ejabberd.
 ##
 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
 ## consumes a lot of memory, send live notifications to these XMPP
index 734efbf6a30abd26e31dc3ced9529c3067fb4a14..f3ae9d86629c3f074a854ef9643eab7f9b4234ee 100755 (executable)
@@ -126,6 +126,24 @@ else
     NAME="-name"
 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
 # then change to that directory readable by INSTALLUSER to
 # prevent "File operation error: eacces." messages
index f5ee863a8be74bb0f9316b1f6cda1e8b45d52af9..65899c8f634a4597170acee1a3e9984976d6a938 100644 (file)
@@ -73,6 +73,18 @@ get_pos_integer_env(Name, Default) ->
                                    [Name, Junk, Default]),
             Default
     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() ->
     application:load(sasl),
@@ -82,6 +94,7 @@ start() ->
     Dir = filename:dirname(ConsoleLog),
     ErrorLog = filename:join([Dir, "error.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),
     LogRotateCount = get_pos_integer_env(log_rotate_count, 1),
     LogRateLimit = get_pos_integer_env(log_rate_limit, 100),
@@ -89,11 +102,12 @@ start() ->
     application:set_env(
       lager, handlers,
       [{lager_console_backend, info},
-       {lager_file_backend, [{file, ConsoleLog}, {level, info},
+       {lager_file_backend, [{file, ConsoleLog}, {level, info}, {date, LogRotateDate},
                              {count, LogRotateCount}, {size, LogRotateSize}]},
-       {lager_file_backend, [{file, ErrorLog}, {level, error},
+       {lager_file_backend, [{file, ErrorLog}, {level, error}, {date, LogRotateDate},
                              {count, LogRotateCount}, {size, LogRotateSize}]}]),
     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_count, LogRotateCount),
     ejabberd:start_app(lager),