Let's say I have a class like below:
#define LOGGER_CLASS_ENABLED
#ifdef LOGGER_CLASS_ENABLED
class Logger{
public:
void println(const String&);
};
Logger this_is_a_singleton_logger;
#define MY_LOGGER this_is_a_singleton_logger
#endif
Throughout my code, whenever I want to log something, I use the following shortcut:
MY_LOGGER.println("Hello")
Now, lets say I want to disable the Logger class. In this scenario, I don't want any logging code to be generated. So, the usual 'C-style' approach is this:
#ifdef LOGGER_CLASS_ENABLED
MY_LOGGER.println("Hello");
#endif
and repeat it for every call.
However, since there are hundreds of such calls, surrounding each print function with an extra two lines everywhere will make the code hard to read. What should I do so that I don't add two lines everywhere, keeping the only a single line of MY_LOGGER.println("Hello"), but make the macro replace it with empty line. Is it possible?
I tried following but it gave me an error:
#ifndef LOGGER_CLASS_ENABLED
#define MY_LOGGER.println(x) // replace it with emtpiness
#endif