summaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-09-06 19:55:23 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-09-06 19:55:23 +0400
commitd1b63d4cff12936a5ea4380bccadcc77b7c3ed3f (patch)
tree33ea284a3c1f5e4c8366fc7eff545cd05c1448d9 /src/util.c
parentab946cd1efd6b2ffcf1080d2a4f4c66dda811ef3 (diff)
downloadrspamd-d1b63d4cff12936a5ea4380bccadcc77b7c3ed3f.tar.gz
rspamd-d1b63d4cff12936a5ea4380bccadcc77b7c3ed3f.zip
* Add ability to call rspamd fucntions from lua api
* Make logging adaptive based on log speed (buffered vs unbuffered IO) * Fix lua API docs * Now lua modules can be loaded with glob patterns
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 3cd24a6eb..61cf56725 100644
--- a/src/util.c
+++ b/src/util.c
@@ -28,6 +28,11 @@
#include "cfg_file.h"
#include "main.h"
+/* Check log messages intensity once per minute */
+#define CHECK_TIME 60
+/* More than 2 log messages per second */
+#define BUF_INTENSITY 2
+
#ifdef RSPAMD_MAIN
sig_atomic_t do_reopen_log = 0;
extern rspamd_hash_t *counters;
@@ -40,6 +45,12 @@ struct logger_params {
static struct logger_params log_params;
+/* Here would be put log messages intensity */
+static uint32_t log_written;
+static time_t last_check;
+static char *io_buf = NULL;
+static gboolean log_buffered = FALSE;
+
int
make_socket_nonblocking (int fd)
{
@@ -651,6 +662,8 @@ open_log (struct config_file *cfg)
return -1;
}
cfg->logf = fdopen (cfg->log_fd, "w");
+ /* Set line buffering */
+ setvbuf (cfg->logf, (char *) NULL, _IOLBF, 0);
return 0;
}
return -1;
@@ -752,9 +765,32 @@ file_log_function (const gchar *log_domain, GLogLevelFlags log_level, const gcha
if (log_level <= cfg->log_level) {
now = time (NULL);
tms = localtime (&now);
+
+ if (last_check == 0) {
+ last_check = now;
+ }
+ else if (now - last_check > CHECK_TIME) {
+ if (log_written / (now - last_check) > BUF_INTENSITY && !log_buffered) {
+ /* Switch to buffered logging */
+ if (io_buf == NULL) {
+ io_buf = g_malloc (BUFSIZ);
+ }
+ setvbuf (cfg->logf, io_buf, _IOFBF, BUFSIZ);
+ log_buffered = TRUE;
+ }
+ else if (log_buffered) {
+ /* Switch to line buffering */
+ setvbuf (cfg->logf, NULL, _IOLBF, 0);
+ log_buffered = FALSE;
+ }
+ last_check = now;
+ log_written = 0;
+ }
+
strftime (timebuf, sizeof (timebuf), "%b %d %H:%M:%S", tms);
snprintf (tmpbuf, sizeof (tmpbuf), "#%d: %s rspamd ", (int)getpid (), timebuf);
fprintf (cfg->logf, "%s%s" CRLF, tmpbuf, message);
+ log_written ++;
}
}