summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/logger.cpp64
-rw-r--r--src/logger.h4
2 files changed, 22 insertions, 46 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())
diff --git a/src/logger.h b/src/logger.h
index f67ec55d1..6fb9fe5d8 100644
--- a/src/logger.h
+++ b/src/logger.h
@@ -88,12 +88,12 @@ class Logger final
/**
* Enters a message in the log. The message will be timestamped.
*/
- void log(std::string str);
+ void log(const std::string &str);
/**
* Enters debug message in the log. The message will be timestamped.
*/
- void dlog(std::string str);
+ void dlog(const std::string &str);
void setDebugLog(const bool n)
{ mDebugLog = n; }