You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
762 B

#ifndef LOGGER_HPP
#define LOGGER_HPP
#include <ostream>
#include <ctime>
#include "Singleton_DCLP.hpp"
class Logger : public Singleton_DCLP<Logger>
{
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