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: 
You could use something like [boost::log](http://boost-log.sourceforge.net/libs/log/doc/html/log/tutorial/trivial_filtering.html) setting severity level to the one you need.

```
void init()
{
    logging::core::get()->set_filter
    (
        flt::attr< logging::trivial::severity_level >("Severity") >= logging::trivial::info
    );
}

int main(int, char*[])
{
    init();

    BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
    BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
    BOOST_LOG_TRIVIAL(info) << "An informational severity message";
    BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
    BOOST_LOG_TRIVIAL(error) << "An error severity message";
    BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";
}

```

I think [pantheios](http://www.pantheios.org/) have something similar too.
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).