A common trick I'm aware of to be able to turn off and on logging is to do something like this:
#ifdef DEBUG
#define debugLog( ... ) printf(__VA_ARGS__)
#else
#define debugLog( ... )
#endif
This way, a debugLog() statement doesn't do anything at all and produces no compiled code when it is deactivated.
However, I'm writing a C++ app, and the logging mechanism I'm using is in the style of std::cout
and requires using the <<
operator.
Is there a way to make a statement like this:
std::cout << "Some important logging:" << foo << bar;
...become a no-op depending on a processor macro?
I want to keep it a single line for purposes of readability. Something like this:
#ifdef DEBUG
std::cout << "....";
#endif
is unacceptable if it's littered all over my code. #ifdef
statements are quite ugly and break apart clean indentation.