Question: During debug mode or while I am doing testing, I need to print lots of various information, so i use this method:

```
#ifdef TESTING
// code with lots of debugging info
#else
// clean code only
#endif // TESTING`

```

Is this a good method, or is there any other simple and elegant method ?

But this way, I am repeating the same code in two places and if anything is to be changed later on in the code, I have to do it in both places, which is time consuming and error prone.

Thanks.

I am using MS Visual Studio.

Answer: 
Use [Log4Cxx](http://logging.apache.org/log4cxx/), instead of rolling your own logging. The Log4Cxx package is highly configurable, supports different levels of logging based on importance/severity, and supports multiple forms of output. 

In addition, unless it is very critical code that must be super optimized, I would recommend leaving logging statements (assuming you use Log4Cxx) in your code, but simply turn down the logging level. That way, logging can be dynamically enabled, which can be incredibly helpful if one of your users experiences a hard-to-replicate bug... just direct them on how to configure a higher logging level. If you completely elide the logging from the executable, then there is no way to obtain that valuable debugging output in the field.
There is a simple way, which works with most compilers:

```
#ifdef TESTING
    #define DPRINTF( args )     printf args
#else
    #define DPRINTF( args )     ((void)0)
#endif

```

Next, in the source code you should use it as:

```
DPRINTF(("Debug: value a = %d, value b = %d\n", a, b));

```

The drawback is that you have to use double parentheses, but in old C and C++
standards variadic macro are not supported (only as a compiler extension).