From 811bac16ecc1a86ba329f6c327d17f04c408d926 Mon Sep 17 00:00:00 2001 From: Sala Leonardo Date: Tue, 9 Sep 2014 17:16:51 +0200 Subject: [PATCH] trying to make it work... --- slsReceiverSoftware/includes/logger.h | 56 +++++++++++---------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/slsReceiverSoftware/includes/logger.h b/slsReceiverSoftware/includes/logger.h index a230a5266..be93f9fac 100644 --- a/slsReceiverSoftware/includes/logger.h +++ b/slsReceiverSoftware/includes/logger.h @@ -10,30 +10,25 @@ inline std::string NowTime(); enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4}; template -class Log -{ -public: - Log(); - virtual ~Log(); - std::ostringstream& Get(TLogLevel level = logINFO); -public: - static TLogLevel& ReportingLevel(); - static std::string ToString(TLogLevel level); - static TLogLevel FromString(const std::string& level); -protected: - std::ostringstream os; -private: - Log(const Log&); - Log& operator =(const Log&); +class Log{ + public: + Log(); + virtual ~Log(); + std::ostringstream& Get(TLogLevel level = logINFO); + public: + static TLogLevel& ReportingLevel(); + static std::string ToString(TLogLevel level); + static TLogLevel FromString(const std::string& level); + protected: + std::ostringstream os; + private: + Log(const Log&); + Log& operator =(const Log&); }; -template -Log::Log() -{ -} +template Log::Log() {} -template -std::ostringstream& Log::Get(TLogLevel level) +template std::ostringstream& Log::Get(TLogLevel level) { os << "- " << NowTime(); os << " " << ToString(level) << ": "; @@ -41,29 +36,25 @@ std::ostringstream& Log::Get(TLogLevel level) return os; } -template -Log::~Log() +template Log::~Log() { os << std::endl; T::Output(os.str()); } -template -TLogLevel& Log::ReportingLevel() +template TLogLevel& Log::ReportingLevel() { static TLogLevel reportingLevel = logDEBUG4; return reportingLevel; } -template -std::string Log::ToString(TLogLevel level) +template std::string Log::ToString(TLogLevel level) { static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4"}; return buffer[level]; } -template -TLogLevel Log::FromString(const std::string& level) +template TLogLevel Log::FromString(const std::string& level) { if (level == "DEBUG4") return logDEBUG4; @@ -85,15 +76,13 @@ TLogLevel Log::FromString(const std::string& level) return logINFO; } -class Output2FILE -{ +class Output2FILE { public: static FILE*& Stream(); static void Output(const std::string& msg); }; -inline FILE*& Output2FILE::Stream() -{ +inline FILE*& Output2FILE::Stream() { static FILE* pStream = stderr; return pStream; } @@ -136,6 +125,7 @@ class FILELOG_DECLSPEC FILELog : public Log {}; #include inline std::string NowTime() + { const int MAX_LEN = 200; char buffer[MAX_LEN];