diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-03-09 17:56:49 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-03-09 17:56:49 +0300 |
commit | d9973824af73a1c4d4ccc3ae814639d6cfbb7e1e (patch) | |
tree | c6aa4dcd9aa6597fc2b4d2a96a8d79ceddd2f764 /src/logger.cpp | |
parent | b6ed79b708090b81eddf48c1425f31f5f10c7494 (diff) | |
download | plus-d9973824af73a1c4d4ccc3ae814639d6cfbb7e1e.tar.gz plus-d9973824af73a1c4d4ccc3ae814639d6cfbb7e1e.tar.bz2 plus-d9973824af73a1c4d4ccc3ae814639d6cfbb7e1e.tar.xz plus-d9973824af73a1c4d4ccc3ae814639d6cfbb7e1e.zip |
Improve logger class.
Diffstat (limited to 'src/logger.cpp')
-rw-r--r-- | src/logger.cpp | 64 |
1 files changed, 20 insertions, 44 deletions
diff --git a/src/logger.cpp b/src/logger.cpp index c6ccbdbe8..2ca474730 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -51,6 +51,21 @@ #include "debug.h" +#define DATESTREAM \ + timeStr << "[" \ + << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") \ + << static_cast<int>(((tv.tv_sec / 60) / 60) % 24) \ + << ":" \ + << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") \ + << static_cast<int>((tv.tv_sec / 60) % 60) \ + << ":" \ + << ((tv.tv_sec % 60 < 10) ? "0" : "") \ + << static_cast<int>(tv.tv_sec % 60) \ + << "." \ + << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") \ + << static_cast<int>((tv.tv_usec / 10000) % 100) \ + << "] "; + Logger::Logger(): mLogToStandardOut(true), mChatWindow(nullptr), @@ -78,12 +93,12 @@ void Logger::setLogFile(const std::string &logFilename) } } -void Logger::log(std::string str) +void Logger::log(const std::string &str) { log("%s", str.c_str()); } -void Logger::dlog(std::string str) +void Logger::dlog(const std::string &str) { if (!mDebugLog) return; @@ -94,20 +109,7 @@ void Logger::dlog(std::string str) // Print the log entry std::stringstream timeStr; - timeStr << "[" - << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") - << static_cast<int>(((tv.tv_sec / 60) / 60) % 24) - << ":" - << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") - << static_cast<int>((tv.tv_sec / 60) % 60) - << ":" - << ((tv.tv_sec % 60 < 10) ? "0" : "") - << static_cast<int>(tv.tv_sec % 60) - << "." - << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") - << static_cast<int>((tv.tv_usec / 10000) % 100) - << "] "; - + DATESTREAM DLOG_ANDROID(str.c_str()) if (mLogFile.is_open()) @@ -128,20 +130,7 @@ void Logger::log1(const char *const buf) // Print the log entry std::stringstream timeStr; - timeStr << "[" - << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") - << static_cast<int>(((tv.tv_sec / 60) / 60) % 24) - << ":" - << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") - << static_cast<int>((tv.tv_sec / 60) % 60) - << ":" - << ((tv.tv_sec % 60 < 10) ? "0" : "") - << static_cast<int>(tv.tv_sec % 60) - << "." - << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") - << static_cast<int>((tv.tv_usec / 10000) % 100) - << "] "; - + DATESTREAM LOG_ANDROID(buf) if (mLogFile.is_open()) @@ -175,20 +164,7 @@ void Logger::log(const char *const log_text, ...) // Print the log entry std::stringstream timeStr; - timeStr << "[" - << ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "") - << static_cast<int>(((tv.tv_sec / 60) / 60) % 24) - << ":" - << (((tv.tv_sec / 60) % 60 < 10) ? "0" : "") - << static_cast<int>((tv.tv_sec / 60) % 60) - << ":" - << ((tv.tv_sec % 60 < 10) ? "0" : "") - << static_cast<int>(tv.tv_sec % 60) - << "." - << (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "") - << static_cast<int>((tv.tv_usec / 10000) % 100) - << "] "; - + DATESTREAM LOG_ANDROID(buf) if (mLogFile.is_open()) |