aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-11-14 15:43:27 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-11-14 15:43:27 +0000
commit2578dd494df557ff527f6ff3611ab718b3e99560 (patch)
treea233ea0ebeda65ba466cebb5226bdfcb90ae910d /src/libutil
parent85de501ef8883db60e8202ff15cf0f8a9a275679 (diff)
downloadrspamd-2578dd494df557ff527f6ff3611ab718b3e99560.tar.gz
rspamd-2578dd494df557ff527f6ff3611ab718b3e99560.zip
[Feature] Add exporter from error ringbuf to ucl
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/logger.c61
-rw-r--r--src/libutil/logger.h7
2 files changed, 68 insertions, 0 deletions
diff --git a/src/libutil/logger.c b/src/libutil/logger.c
index 2887a69de..28ef64411 100644
--- a/src/libutil/logger.c
+++ b/src/libutil/logger.c
@@ -1139,3 +1139,64 @@ rspamd_log_lock (rspamd_logger_t *logger)
logger->no_lock = FALSE;
}
}
+
+static gint
+rspamd_log_errlog_cmp (const ucl_object_t **o1, const ucl_object_t **o2)
+{
+ const ucl_object_t *ts1, *ts2;
+
+ ts1 = ucl_object_lookup (*o1, "ts");
+ ts2 = ucl_object_lookup (*o2, "ts");
+
+ if (ts1 && ts2) {
+ return ucl_object_toint (ts2) - ucl_object_toint (ts1);
+ }
+
+ return 0;
+}
+
+ucl_object_t *
+rspamd_log_errorbuf_export (const rspamd_logger_t *logger)
+{
+ struct rspamd_logger_error_elt *cpy, *cur;
+ ucl_object_t *top = ucl_object_typed_new (UCL_ARRAY);
+ guint i;
+
+ if (logger->errlog == NULL) {
+ return top;
+ }
+
+ cpy = g_malloc0_n (logger->errlog->max_elts,
+ sizeof (*cpy) + logger->errlog->elt_len);
+ memcpy (cpy, logger->errlog->elts, logger->errlog->max_elts *
+ (sizeof (*cpy) + logger->errlog->elt_len));
+
+ for (i = 0; i < logger->errlog->max_elts; i ++) {
+ cur = (struct rspamd_logger_error_elt *)((guchar *)cpy +
+ i * ((sizeof (*cpy) + logger->errlog->elt_len)));
+ if (cur->completed) {
+ ucl_object_t *obj = ucl_object_typed_new (UCL_OBJECT);
+
+ ucl_object_insert_key (obj, ucl_object_fromint (cur->ts),
+ "ts", 0, false);
+ ucl_object_insert_key (obj, ucl_object_fromint (cur->pid),
+ "pid", 0, false);
+ ucl_object_insert_key (obj,
+ ucl_object_fromstring (g_quark_to_string (cur->ptype)),
+ "type", 0, false);
+ ucl_object_insert_key (obj, ucl_object_fromstring (cur->id),
+ "id", 0, false);
+ ucl_object_insert_key (obj, ucl_object_fromstring (cur->module),
+ "module", 0, false);
+ ucl_object_insert_key (obj, ucl_object_fromstring (cur->message),
+ "message", 0, false);
+
+ ucl_array_append (top, obj);
+ }
+ }
+
+ ucl_object_array_sort (top, rspamd_log_errlog_cmp);
+ g_free (cpy);
+
+ return top;
+}
diff --git a/src/libutil/logger.h b/src/libutil/logger.h
index f3ba9da28..d596e54e8 100644
--- a/src/libutil/logger.h
+++ b/src/libutil/logger.h
@@ -150,6 +150,13 @@ void rspamd_log_lock (rspamd_logger_t *logger);
*/
const guint64* rspamd_log_counters (rspamd_logger_t *logger);
+/**
+ * Returns errors ring buffer as ucl array
+ * @param logger
+ * @return
+ */
+ucl_object_t * rspamd_log_errorbuf_export (const rspamd_logger_t *logger);
+
/* Typical functions */
/* Logging in postfix style */