In our application, we created our own logging system. There are several different log types, debug, error, warning, communication, performance and ..., in this logging system. There are lots of #ifdef and #endif to disable a specific log type. These #ifdef and #endif make the code hard to read.
We are thinking remove these #ifdef and #endif and have a check before the message write to the file. That means there are lots of "useless" calls to the logging system. These calls will not result in any writing activity.
Is there a better way to turn on/off a log type, without these #ifdef and #endif AND
these "useless" calls?
What about the following:
// comment out if not needed
#define ENABLE_LOG
#ifdef ENABLE_LOG
# define LOG(x) x
#else
# define LOG(x) (void) 0
#endif
Later you could just call:
LOG(mylogger.call());
Updated the #else
part as Dietrich Epp suggested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With