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.
I'm writing for embedded systems in C. 
In my programs I'm using following macros:

```

#define _L  log_stamp(__FILE__, __LINE__)

#define _LS(a)  log_string(a)

#define _LI(a)  log_long(a)

#define _LA(a,l)  log_array(a,l)

#define _LH(a)  log_hex(a)

#define _LC(a)  log_char(a)

#define ASSERT(con) log_assert(__FILE__, __LINE__, con)

```

When I'm making release version, I simply switch off #define DEBUG directive and all macros become empty. 
Note that it doesn't consume any CPU cycles and memory in release version.
Macros are the only way to save to log information: where the logging was done 
(file and line number).

If I need this information I use:
`_L;_LS("this is a log message number ");_LI(5);`

otherwise without `_L` directive.