#ifndef LOGGER_HPP #define LOGGER_HPP #include #include #include "Singleton_DCLP.hpp" class Logger : public Singleton_DCLP { public: Logger() : m_os(nullptr), m_print_time_stamp(false) {} void setStream(std::ostream* os) { m_os = os; } std::ostream* getStream() { if (m_print_time_stamp) { const std::time_t timenow = std::time(nullptr); std::string s(std::ctime(&timenow)); s.pop_back(); // removing trailing \n *m_os << s << " "; } return m_os; } void setPrintTimeStamp(bool b = true) { m_print_time_stamp = b; } private: // ostreams are not copyable, hence storing a pointer only std::ostream* m_os; bool m_print_time_stamp; }; #define LOG *Logger::getInstance()->getStream() #endif // LOGGER_HPP