[CRIU] [PATCH 04/14] soccr: Add logging
Pavel Emelyanov
xemul at virtuozzo.com
Mon Apr 18 06:03:35 PDT 2016
In order to get messages from libsoccr I propose to
introduce a printing callback that can be set by library
user and that will be called by libsoccr.
Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
soccr/soccr.c | 13 +++++++++++++
soccr/soccr.h | 9 +++++++++
2 files changed, 22 insertions(+)
diff --git a/soccr/soccr.c b/soccr/soccr.c
index f33c50c..98b8f47 100644
--- a/soccr/soccr.c
+++ b/soccr/soccr.c
@@ -1 +1,14 @@
#include "soccr.h"
+
+static void (*log)(unsigned int loglevel, const char *format, ...)
+ __attribute__ ((__format__ (__printf__, 2, 3)));
+static unsigned int log_level = 0;
+
+void libsoccr_set_log(unsigned int level, void (*fn)(unsigned int level, const char *fmt, ...))
+{
+ log_level = level;
+ log = fn;
+}
+
+#define loge(msg, ...) do { if (log && (log_level >= SOCCR_LOG_ERR)) log(SOCCR_LOG_ERR, msg, ##__VA_ARGS__); } while (0)
+#define logd(msg, ...) do { if (log && (log_level >= SOCCR_LOG_DBG)) log(SOCCR_LOG_DBG, msg, ##__VA_ARGS__); } while (0)
diff --git a/soccr/soccr.h b/soccr/soccr.h
index eaae1a2..07d7947 100644
--- a/soccr/soccr.h
+++ b/soccr/soccr.h
@@ -1,3 +1,12 @@
#ifndef __LIBSOCCR_H__
#define __LIBSOCCR_H__
+#include <linux/types.h>
+
+struct libsoccr_sk;
+
+void libsoccr_set_log(unsigned int level, void (*fn)(unsigned int level, const char *fmt, ...));
+
+#define SOCCR_LOG_ERR 1
+#define SOCCR_LOG_DBG 2
+
#endif
--
2.5.0
More information about the CRIU
mailing list