#ifndef DEBUG_H #define DEBUG_H #include #include #include #include #include "Time.h" #include "log/LoggerCOUT.h" /** quick and dirty workaround */ static decltype(Time::tick()) LogLastTick; #ifdef WITH_DEBUG_LOG class Log { private: static Logger** getLoggerPtr() { static Logger* logger = new LoggerCOUT(); return &logger; } static Logger* getLogger() { return *getLoggerPtr(); } public: /** set the to-be-used logger */ static void setLogger(Logger* logger) { *getLoggerPtr() = logger; } static void add(const char* comp, const std::string what, const bool nl = true) { std::stringstream out; addComp(out, comp); out << what; getLogger()->add(out.str(), nl); } static void add(const std::string& component, const std::string what, const bool nl = true) { std::stringstream out; addComp(out, component.c_str()); out << what; getLogger()->add(out.str(), nl); } static void tick() { LogLastTick = Time::tick(); } static void tock() { const auto cur = Time::tick(); const int diff_ms = Time::diffMS(LogLastTick, cur); LogLastTick = cur; std::stringstream out; out << " (took: " << diff_ms << "ms)"; getLogger()->add(out.str(), true); } private: static void addComp(std::ostream& out, const char* component) { out << "[" << std::setw(12) << std::setfill(' ') << component << "] "; } }; #else class Log { public: static void add(const char* comp, const std::string what, const bool nl = true) { (void)comp; (void) what; (void) nl; } static void add(const std::string& component, const std::string what, const bool nl = true) { (void)component; (void) what; (void) nl; } static void tick() {;} static void tock() {;} }; #endif #endif // DEBUG_H