summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-08-31 14:32:24 +0300
committerAndrei Karas <akaras@inbox.ru>2014-08-31 14:32:24 +0300
commitca49316628e8e3e6161d9a9649893664ef36c925 (patch)
tree77ffbc587bdf78c81b18b0f671e1119c487860f2
parent544de86739a85792be7e6883968b2af8590d0711 (diff)
downloadmanaplus-ca49316628e8e3e6161d9a9649893664ef36c925.tar.gz
manaplus-ca49316628e8e3e6161d9a9649893664ef36c925.tar.bz2
manaplus-ca49316628e8e3e6161d9a9649893664ef36c925.tar.xz
manaplus-ca49316628e8e3e6161d9a9649893664ef36c925.zip
Improve packets logging speed.
-rw-r--r--src/logger.cpp31
-rw-r--r--src/logger.h15
2 files changed, 35 insertions, 11 deletions
diff --git a/src/logger.cpp b/src/logger.cpp
index d53ebc99b..024de4660 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -119,6 +119,37 @@ void Logger::dlog(const std::string &str)
if (mLogToStandardOut)
std::cout << timeStr.str() << str << std::endl;
}
+
+void Logger::dlog2(const std::string &str, const char* const comment)
+{
+ if (!mDebugLog)
+ return;
+
+ // Get the current system time
+ timeval tv;
+ gettimeofday(&tv, nullptr);
+
+ // Print the log entry
+ std::stringstream timeStr;
+ DATESTREAM
+ DLOG_ANDROID(str.c_str())
+
+ if (mLogFile.is_open())
+ {
+ if (comment)
+ mLogFile << timeStr.str() << str << ": " << comment << std::endl;
+ else
+ mLogFile << timeStr.str() << str << std::endl;
+ }
+
+ if (mLogToStandardOut)
+ {
+ if (comment)
+ std::cout << timeStr.str() << str << ": " << comment << std::endl;
+ else
+ std::cout << timeStr.str() << str << std::endl;
+ }
+}
#endif
void Logger::log1(const char *const buf)
diff --git a/src/logger.h b/src/logger.h
index e26d3e6e6..8eafc70af 100644
--- a/src/logger.h
+++ b/src/logger.h
@@ -41,18 +41,9 @@
#ifdef ENABLEDEBUGLOG
#define DEBUGLOG2(msg, comment) \
if (logger) \
- { \
- if (comment) \
- { \
- logger->dlog(std::string(msg).append(": ").append(comment)); \
- } \
- else \
- { \
- logger->dlog(msg); \
- } \
- }
+ logger->dlog2(msg, comment)
#else
-#define DEBUGLOG(msg) {}
+#define DEBUGLOG2(msg, comment) {}
#endif
/**
@@ -127,6 +118,8 @@ class Logger final
* Enters debug message in the log. The message will be timestamped.
*/
void dlog(const std::string &str);
+
+ void dlog2(const std::string &str, const char* const comment);
#endif
void setDebugLog(const bool n)