summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>2013-11-12 21:33:09 +1000
committerChristophe Romain <christophe.romain@process-one.net>2014-07-02 14:58:58 +0200
commitbb8a0f71e6faf6aafdd17e78581816c2e0440c2c (patch)
tree631be9373dd906e3998afc7fc815a2f550ef4d84
parentDisable SASL error logger if lager is enabled (diff)
Support new options: log_rotate_size and log_rate_limit
-rw-r--r--doc/guide.tex31
-rw-r--r--src/ejabberd_logger.erl22
2 files changed, 46 insertions, 7 deletions
diff --git a/doc/guide.tex b/doc/guide.tex
index ad7bd407..7a469de3 100644
--- a/doc/guide.tex
+++ b/doc/guide.tex
@@ -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.
diff --git a/src/ejabberd_logger.erl b/src/ejabberd_logger.erl
index e19c6a42..7c47b8b7 100644
--- a/src/ejabberd_logger.erl
+++ b/src/ejabberd_logger.erl
@@ -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.