30 #if defined(_MSC_VER) && _MSC_VER < 1900 31 #define snprintf _snprintf 38 void (*msg_callback)(
int level,
char* msg);
41 static debug_ctx_t debug_ctx = {LIBTAG, DBG_NONE, NULL};
49 static inline void __dbg_setlevel(
debug_ctx_t* ctx,
int level)
53 ctx->cur_level = level;
63 static inline void __dbg(
debug_ctx_t* ctx,
int level,
const char* fmt, va_list ap)
65 if (ctx != NULL && level <= ctx->cur_level)
68 int len = snprintf(msg,
sizeof (msg),
"(%s)", ctx->name);
69 vsnprintf(msg + len,
sizeof (msg) - len, fmt, ap);
70 if (ctx->msg_callback)
72 ctx->msg_callback(level, msg);
76 fwrite(msg, strlen(msg), 1, stderr);
81 void NSROOT::DBGLevel(
int l)
83 __dbg_setlevel(&debug_ctx, l);
88 __dbg_setlevel(&debug_ctx, DBG_ALL);
91 void NSROOT::DBGNone()
93 __dbg_setlevel(&debug_ctx, DBG_NONE);
96 void NSROOT::DBG(
int level,
const char* fmt, ...)
101 __dbg(&debug_ctx, level, fmt, ap);
105 void NSROOT::SetDBGMsgCallback(
void (*msgcb)(
int level,
char*))
107 debug_ctx.msg_callback = msgcb;