util: BlackholeLogger, a quiet Logger drop-in replacement

The compiler should be able to completely optimize away side-effect
free usage of this logger.  Can be used as a drop-in replacement for
Loggers to silence logging output for known-good code without having
to remove the corresponding "LOG << ..." code.

Change-Id: Ifb276223f61686773dd6108aafd567e99c88b223
This commit is contained in:
Horst Schirmeier
2014-04-29 18:24:26 +02:00
parent a198eda8c8
commit b92df6592f

View File

@ -0,0 +1,25 @@
#ifndef __BLACKHOLE_LOGGER_HPP__
#define __BLACKHOLE_LOGGER_HPP__
#include <iostream>
namespace fail {
/**
* \class BlackholeLogger
* A /dev/null sink as a drop-in replacement for Logger. Should be completely
* optimized away on non-trivial optimization levels.
*/
class BlackholeLogger {
public:
Logger(const std::string& description = "Fail*", bool show_time = true,
std::ostream& dest = std::cout) { }
void setDescription(const std::string& descr) { }
void showTime(bool choice) { }
template<class T>
inline std::ostream& operator <<(const T& v) { }
};
} // end-of-namespace: fail
#endif // __BLACKHOLE_LOGGER_HPP__