I contribute to an open source c++ application. In that application is all logging done with lines such as
if (Debug) std::cout << "MyClass | my debug message" << MyExpensiveStringConvertion() << std::endl;
being used to use more advanced logging framework (in other languages) I suggested using one of the existing frameworks such as boost, easylogginppp, whatever that does automatic formating and can be configured at runtime.
but I was replied that using "if (Debug)" has almost no overhead while writting
Log(debug) << "MyClass | my debug message" << MyExpensiveStringConvertion()
requires both the computation of << operator and MyExpensiveStringConvertion() event when logging is disabled. Is this argument correct? if it is correct, should we care? Looks like most logging framework work that way so obviously most developers do not care
update: I understand if (Debug) form only require a simple bool test but I was expecting logging frameworks to implement all kinds of tricks to reduce cost like the "#define LOG(level) if (doDebug(level)) Log(level)" that Dietmar Kühl mentionned.