by design, in the environment I’m working right now I can’t use a debugger to try to detect bugs, so pretty much always when I need to debug a functionality I end up outputting some info.
To do that I’ve done the following:
#ifdef DEBUG
#define printd(x) printf x
#else
#define printd(x)
#endif
So when I need to print some debug info I use printd() instead of printf().
The problem I’ve found is that I need a leveled system, there are messages that may be important in a determined debug level, but irrelevant when debugging other parts of the code.
So my question is, how can I implement a leveled debug system? I value simplicity, I mean, I prefer my actual system than needing a lot of code or confusing code when using it. Something like printd(level, format, ...) would be awesome.
Sure, there are more elegant ways to do this, of course, but this works just fine
Although personally I prefer this
where
printdfis a function that tests the level and then callsvprintfpassing along the fmt and va_args.