#include "log.hh" #include #include #include /** * \author cpellegrino */ using namespace JPP; class MLSing { MLSing() {} JMessageLoggerThreadSafe m_mlts; public: static MLSing& get() { static MLSing sing; return sing; } void init(JMessageLoggerThreadSafe const& second) { m_mlts = second; } JMessageLoggerThreadSafe& logger() { return m_mlts; } }; void initLogger(JMessageLoggerThreadSafe const& second) { MLSing::get().init(second); } void setLogLevel(int level) { // This shall be protected from race conditions with a mutex to avoid UB. // But this very UB won't really produce any problem, hopefully. MLSing::get().logger().setLevel(level); } Log::Logger::~Logger() { if (m_level == cError) { JLOGGER::JErrorStream(MLSing::get().logger()) << m_stream.str(); } else if (m_level == cWarning) { JLOGGER::JWarningStream(MLSing::get().logger()) << m_stream.str(); } else if (m_level == cNotice) { JLOGGER::JNoticeStream (MLSing::get().logger()) << m_stream.str(); } else if (m_level == cStatus) { JLOGGER::JStatusStream (MLSing::get().logger()) << m_stream.str(); } else if (m_level == cDebug) { JLOGGER::JDebugStream (MLSing::get().logger()) << m_stream.str(); } }