Support new options: log_rotate_size and log_rate_limit
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Tue, 12 Nov 2013 11:33:09 +0000 (21:33 +1000)
committerChristophe Romain <christophe.romain@process-one.net>
Wed, 2 Jul 2014 12:58:58 +0000 (14:58 +0200)
doc/guide.tex
src/ejabberd_logger.erl

index ad7bd407c875b78ce0f5d53c09060b225bca9900..7a469de3b30e880b5e15b40b543471addbdb9292 100644 (file)
@@ -6015,10 +6015,11 @@ The syntax is:
 
 \makesection{logfiles}{Log Files}
 
-An \ejabberd{} node writes two log files:
+An \ejabberd{} node writes three log files:
 \begin{description}
        \titem{ejabberd.log} is the ejabberd service log, with the messages reported by \ejabberd{} code
-       \titem{erlang.log} is the Erlang/OTP system log, with the messages reported by Erlang/OTP using SASL (System Architecture Support Libraries)
+        \titem{error.log} is the file accumulating error messages from \term{ejabberd.log}
+       \titem{crash.log} is the Erlang/OTP log, with the crash messages reported by Erlang/OTP using SASL (System Architecture Support Libraries)
 \end{description}
 
 The option \term{loglevel} modifies the verbosity of the file ejabberd.log. The syntax:
@@ -6040,14 +6041,34 @@ For example, the default configuration is:
 loglevel: 4
 \end{verbatim}
 
-The log files grow continually, so it is recommended to rotate them periodically.
-To rotate the log files, rename the files and then reopen them.
+Option \term{log\_rate\_limit} is useful if you want to protect the logging
+mechanism from being overloaded by excessive amount of log messages.
+The syntax is:
+\begin{description}
+  \titem{log\_rate\_limit: N} Where N is a maximum number of log messages per second.
+  The default value is 100.
+\end{description}
+When the limit is reached the similar warning message is logged:
+\begin{verbatim}
+lager_error_logger_h dropped 800 messages in the last second that exceeded the limit of 100 messages/sec
+\end{verbatim}
+
+By default \ejabberd{} rotates the log files when they get grown above a certain size.
+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).
+\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.
 The ejabberdctl command \term{reopen-log} 
 (please refer to section \ref{ectl-commands})
 reopens the log files,
 and also renames the old ones if you didn't rename them.
 
-
 \makesection{debugconsole}{Debug Console}
 
 The Debug Console is an Erlang shell attached to an already running \ejabberd{} server.
index e19c6a428d0e8eb20fcb62db2d4791e0ec2487fd..7c47b8b7271387befc4805e2231a8f95099ef998 100644 (file)
@@ -61,6 +61,19 @@ get_log_path() ->
 
 -ifdef(LAGER).
 
+get_pos_integer_env(Name, Default) ->
+    case application:get_env(ejabberd, Name) of
+        {ok, I} when is_integer(I), I>0 ->
+            I;
+        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),
     application:set_env(sasl, sasl_error_logger, false),
@@ -69,11 +82,16 @@ start() ->
     Dir = filename:dirname(ConsoleLog),
     ErrorLog = filename:join([Dir, "error.log"]),
     CrashLog = filename:join([Dir, "crash.log"]),
+    LogRotateSize = get_pos_integer_env(log_rotate_size, 10*1024*1024),
+    LogRateLimit = get_pos_integer_env(log_rate_limit, 100),
+    application:set_env(lager, error_logger_hwm, LogRateLimit),
     application:set_env(
       lager, handlers,
       [{lager_console_backend, info},
-       {lager_file_backend, [{file, ConsoleLog}, {level, info}, {count, 1}]},
-       {lager_file_backend, [{file, ErrorLog}, {level, error}, {count, 1}]}]),
+       {lager_file_backend, [{file, ConsoleLog}, {level, info},
+                             {count, 1}, {size, LogRotateSize}]},
+       {lager_file_backend, [{file, ErrorLog}, {level, error},
+                             {count, 1}, {size, LogRotateSize}]}]),
     application:set_env(lager, crash_log, CrashLog),
     ejabberd:start_app(lager),
     ok.