[CRIU] [PATCH 7/8] libsoccr: Add ability to provide log level mappings

Cyrill Gorcunov gorcunov at openvz.org
Wed Nov 1 16:19:24 MSK 2017


Otherwise it might be impossible to notify a calling
side for certain level.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 soccr/soccr.c | 30 +++++++++++++++++++++++++++---
 soccr/soccr.h |  2 ++
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/soccr/soccr.c b/soccr/soccr.c
index 394095f00556..daf5dbbc1279 100644
--- a/soccr/soccr.c
+++ b/soccr/soccr.c
@@ -67,6 +67,12 @@ enum {
 static void (*log)(unsigned int loglevel, const char *format, ...)
 	__attribute__ ((__format__ (__printf__, 2, 3)));
 static unsigned int log_level = 0;
+static unsigned int *log_level_map;
+
+void libsoccr_set_log_level_map(unsigned int *map)
+{
+	log_level_map = map;
+}
 
 void libsoccr_set_log(unsigned int level, void (*fn)(unsigned int level, const char *fmt, ...))
 {
@@ -74,9 +80,27 @@ void libsoccr_set_log(unsigned int level, void (*fn)(unsigned int level, const c
 	log = fn;
 }
 
-#define loge(msg, ...) do { if (log && (log_level >= SOCCR_LOG_ERR)) log(SOCCR_LOG_ERR, "Error (%s:%d): " msg, __FILE__, __LINE__, ##__VA_ARGS__); } while (0)
-#define logerr(msg, ...) loge(msg ": %s\n", ##__VA_ARGS__, strerror(errno))
-#define logd(msg, ...) do { if (log && (log_level >= SOCCR_LOG_DBG)) log(SOCCR_LOG_DBG, "Debug: " msg, ##__VA_ARGS__); } while (0)
+#define loge(msg, ...)							\
+	do {								\
+		if (log && (log_level >= SOCCR_LOG_ERR))		\
+			log(log_level_map ?				\
+			    log_level_map[SOCCR_LOG_ERR] :		\
+			    SOCCR_LOG_ERR,				\
+			    "Error (%s:%d): " msg,			\
+			    __FILE__, __LINE__, ##__VA_ARGS__);		\
+	} while (0)
+
+#define logerr(msg, ...)						\
+	loge(msg ": %s\n", ##__VA_ARGS__, strerror(errno))		\
+
+#define logd(msg, ...)							\
+	do {								\
+		if (log && (log_level >= SOCCR_LOG_DBG))		\
+			log(log_level_map ?				\
+			    log_level_map[SOCCR_LOG_DBG] :		\
+			    SOCCR_LOG_DBG,				\
+			    "Debug: " msg, ##__VA_ARGS__);		\
+	} while (0)
 
 static int tcp_repair_on(int fd)
 {
diff --git a/soccr/soccr.h b/soccr/soccr.h
index 2c34e169b2e7..c0695eaeaee8 100644
--- a/soccr/soccr.h
+++ b/soccr/soccr.h
@@ -55,6 +55,8 @@ void libsoccr_set_log(unsigned int level, void (*fn)(unsigned int level, const c
 #define SOCCR_LOG_ERR	1
 #define SOCCR_LOG_DBG	2
 
+extern void libsoccr_set_log_level_map(unsigned int *map);
+
 /*
  * An opaque handler for C/R-ing a TCP socket.
  */
-- 
2.7.5



More information about the CRIU mailing list