|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
#ifndef LOGGER_HPP
|
|
|
|
|
#define LOGGER_HPP
|
|
|
|
|
|
|
|
|
|
#include <ostream>
|
|
|
|
|
#include <ctime>
|
|
|
|
|
|
|
|
|
|
#include <ostream>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
#include "Singleton_DCLP.hpp"
|
|
|
|
|
|
|
|
|
|
class Logger : public Singleton_DCLP<Logger>
|
|
|
|
@ -11,22 +13,23 @@ class Logger : public Singleton_DCLP<Logger>
|
|
|
|
|
public:
|
|
|
|
|
class Endl {};
|
|
|
|
|
|
|
|
|
|
Logger() : m_os(nullptr), m_print_time_stamp(false) {}
|
|
|
|
|
Logger() : m_os(nullptr), m_buffer(), m_print_time_stamp(false) {}
|
|
|
|
|
|
|
|
|
|
void setStream(std::ostream* os) { m_os = os; }
|
|
|
|
|
std::ostream* getStream() { return m_os; }
|
|
|
|
|
|
|
|
|
|
void setPrintTimeStamp(bool b = true) { m_print_time_stamp = b; }
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
|
Logger &operator<<(const T &x) {
|
|
|
|
|
decorate();
|
|
|
|
|
*m_os << x;
|
|
|
|
|
m_buffer << x;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger& operator<<(const Logger::Endl& e) {
|
|
|
|
|
decorate();
|
|
|
|
|
*m_os << m_buffer.str();
|
|
|
|
|
*m_os << std::endl;
|
|
|
|
|
m_buffer.str("");
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -43,6 +46,7 @@ private:
|
|
|
|
|
|
|
|
|
|
// ostreams are not copyable, hence storing a pointer only
|
|
|
|
|
std::ostream* m_os;
|
|
|
|
|
std::ostringstream m_buffer;
|
|
|
|
|
bool m_print_time_stamp;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|