From b92df6592fc9acbb4e9fa02335c931389d47b6fa Mon Sep 17 00:00:00 2001 From: Horst Schirmeier Date: Tue, 29 Apr 2014 18:24:26 +0200 Subject: [PATCH] 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 --- src/core/util/BlackholeLogger.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/core/util/BlackholeLogger.hpp diff --git a/src/core/util/BlackholeLogger.hpp b/src/core/util/BlackholeLogger.hpp new file mode 100644 index 00000000..6ef1674f --- /dev/null +++ b/src/core/util/BlackholeLogger.hpp @@ -0,0 +1,25 @@ +#ifndef __BLACKHOLE_LOGGER_HPP__ +#define __BLACKHOLE_LOGGER_HPP__ + +#include + +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 + inline std::ostream& operator <<(const T& v) { } +}; + +} // end-of-namespace: fail + +#endif // __BLACKHOLE_LOGGER_HPP__