c - How to implement a leveled debug system? -
In the environment, I am working now, I can not use the debugger to detect the bug, so much More always when I need to debug a functionality, I have to output some information.
I did the following to do this:
#ifdef DEBUG #define printd (X) printf x #else #define printd (x) #endif
So when I need to print some debug info, then I printd ()
instead of printf ()
.
The problem I got is that I need a leveling system, there are messages that can be important in the fixed debug level, but irrelevant code when debugging other parts.
So my question is, how do I implement an equivalent debug system? I value the simplicity, I mean, I prefer my actual system much more than the need for a lot of code or confuse me using code. Something like printd (level, format, ...)
would be great.
Of course, there are more aromatic methods to do this, but it works just fine
#ifdef DEBUG extern int g_debuglevel; #define printd (level, x) (level> lp = g_debuglevel)? 0: printf x #else #define printd (level, x) #endif
Although personally I like it
#ifdef DEBUG extern zero Printdf (level, fmt, ...); #define printd printfd #else #define printd #endif
Where printdf
is a function that checks the level and then vprintf
Calling with FMT and VA_Garg.
Comments
Post a Comment