aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-09-25 13:17:55 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-09-25 13:17:55 +0100
commitc742eeba369cfce062f2464c8cb3e62405025185 (patch)
tree0fb71a49467f174813ff6f6da6d806b44d22be2c /src
parent219288ea4ffd24399d110b28ff790bcf78eb6532 (diff)
downloadrspamd-c742eeba369cfce062f2464c8cb3e62405025185.tar.gz
rspamd-c742eeba369cfce062f2464c8cb3e62405025185.zip
Add logger counters.
Diffstat (limited to 'src')
-rw-r--r--src/libutil/logger.c42
-rw-r--r--src/libutil/logger.h9
2 files changed, 40 insertions, 11 deletions
diff --git a/src/libutil/logger.c b/src/libutil/logger.c
index 105b59375..82fbf64ab 100644
--- a/src/libutil/logger.c
+++ b/src/libutil/logger.c
@@ -67,6 +67,7 @@ struct rspamd_logger_s {
gchar *saved_id;
rspamd_mempool_t *pool;
rspamd_mempool_mutex_t *mtx;
+ guint64 log_cnt[4];
};
static const gchar lf_chr = '\n';
@@ -434,17 +435,36 @@ rspamd_common_logv (rspamd_logger_t *rspamd_log, GLogLevelFlags log_level,
fprintf (stderr, "%s\n", logbuf);
}
}
- else if (rspamd_logger_need_log (rspamd_log, log_level, module)) {
- rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, args);
- rspamd_escape_log_string (logbuf);
- rspamd_mempool_lock_mutex (rspamd_log->mtx);
- rspamd_log->log_func (NULL, module, id,
- function,
- log_level,
- logbuf,
- FALSE,
- rspamd_log);
- rspamd_mempool_unlock_mutex (rspamd_log->mtx);
+ else {
+ if (rspamd_logger_need_log (rspamd_log, log_level, module)) {
+ rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, args);
+ rspamd_escape_log_string (logbuf);
+ rspamd_mempool_lock_mutex (rspamd_log->mtx);
+ rspamd_log->log_func (NULL, module, id,
+ function,
+ log_level,
+ logbuf,
+ FALSE,
+ rspamd_log);
+ rspamd_mempool_unlock_mutex (rspamd_log->mtx);
+ }
+
+ switch (log_level) {
+ case G_LOG_LEVEL_CRITICAL:
+ rspamd_log->log_cnt[0] ++;
+ break;
+ case G_LOG_LEVEL_WARNING:
+ rspamd_log->log_cnt[1]++;
+ break;
+ case G_LOG_LEVEL_INFO:
+ rspamd_log->log_cnt[2]++;
+ break;
+ case G_LOG_LEVEL_DEBUG:
+ rspamd_log->log_cnt[3]++;
+ break;
+ default:
+ break;
+ }
}
}
diff --git a/src/libutil/logger.h b/src/libutil/logger.h
index e8c71465b..42307fc6c 100644
--- a/src/libutil/logger.h
+++ b/src/libutil/logger.h
@@ -123,6 +123,15 @@ void rspamd_log_debug (rspamd_logger_t *logger);
*/
void rspamd_log_nodebug (rspamd_logger_t *logger);
+/**
+ * Return array of counters (4 numbers):
+ * 0 - errors
+ * 1 - warnings
+ * 2 - info messages
+ * 3 - debug messages
+ */
+const guint64* rspamd_log_counters (rspamd_logger_t *logger);
+
/* Typical functions */
/* Logging in postfix style */