#ifndef LOG_HPP #define LOG_HPP #include #include #include namespace log { struct Logger { Logger(std::ostream& stream, const std::string& name) : _stream(stream), _name(name), _enabled(false) {} bool enabled() const { return _enabled; } bool enabled(bool v) { bool ret = _enabled; _enabled = v; return ret; } template friend Logger& operator<<(Logger&, const T&); private: std::ostream& _stream; std::string _name; bool _enabled; }; template Logger& operator<<(Logger& logger, const T& obj) { if (logger._enabled) { logger._stream << logger._name << " :- " << obj << std::endl; } return logger; } Logger trace(std::cerr, "trace"); Logger strategy(std::cerr, "strategy"); Logger debug(std::cerr, "debug"); } #endif