]> source.dussan.org Git - rspamd.git/commitdiff
Add logger counters.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 25 Sep 2015 12:17:55 +0000 (13:17 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 25 Sep 2015 12:17:55 +0000 (13:17 +0100)
src/libutil/logger.c
src/libutil/logger.h

index 105b593750deb37f549fdf3fd65f0528323b7a8d..82fbf64ab263233080d0a7a9f9631387ae12e71c 100644 (file)
@@ -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;
+               }
        }
 }
 
index e8c71465bbc4dc3efa853e1d77438960e33ba480..42307fc6c0d334277bc3c5cb84a2982c61a5897b 100644 (file)
@@ -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 */