The severity level of the log entries acts as a filter for receivers. The sink will decide what to do with the message (type it or not) depending on the severity level. But the message will still be sent.
If you are not trying to send a message at all, you need to redefine LOG_MESSAGE to actually do nothing. there may be something in the Boost library for this, otherwise you will have to write your own. Perhaps this will be the beginning:
class NullLogger { public: template <typename SeverityT> NullLogger (SeverityT) {}; template <typename Val> NullLog& operator<< (const Val&) { return * this}; };
... and then:
#define LOG_MESSAGE (lvl) NullLogger (lvl)
Note that although nothing is done with the log message or the expressions that make up it, the expressions are still evaluated. If some of these expressions are expensive, you will still get a performance hit. For instance:
LOG_MESSAGE (debug) << SomeSuperExpensiveFunction();
Even if you use the NullLogger above, SomeSuperExpensiveFunction() will still be called.
I would suggest, as an alternative, add a flag that evaluates at runtime and decide at runtime whether the log should be kept:
if (mLogStuff) { LOG_MESSAGE (debug) << SomeSuperExpensiveFunction(); }
bool Comparing ean is very cheap, and in the future you may find that turning logging on and off can be very convenient. In addition, this means that you do not need to add another #define , which is always good.
source share