Commit e3f270ac authored by Pavel Emelyanov's avatar Pavel Emelyanov

soccr: Add logging

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: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 6d9e6d15
#include "soccr.h" #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)
#ifndef __LIBSOCCR_H__ #ifndef __LIBSOCCR_H__
#define __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 #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment