summaryrefslogtreecommitdiff
path: root/src/logger.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-04-30 02:03:32 +0300
committerAndrei Karas <akaras@inbox.ru>2016-04-30 02:03:32 +0300
commit244991dee7a2e274cb361f5040dd39b0f2997290 (patch)
tree1561cedb98b1f2df73fb49cc26f48eb14d01e520 /src/logger.cpp
parent22795c4301cd6b62a8270b45a72a850ed888daf8 (diff)
downloadmanaplus-244991dee7a2e274cb361f5040dd39b0f2997290.tar.gz
manaplus-244991dee7a2e274cb361f5040dd39b0f2997290.tar.bz2
manaplus-244991dee7a2e274cb361f5040dd39b0f2997290.tar.xz
manaplus-244991dee7a2e274cb361f5040dd39b0f2997290.zip
Extend assert reporting functions with condition text and call stack.
Diffstat (limited to 'src/logger.cpp')
-rw-r--r--src/logger.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/logger.cpp b/src/logger.cpp
index f61cd2464..395daa135 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -264,6 +264,45 @@ void Logger::log(const char *const log_text, ...)
delete [] buf;
}
+void Logger::assert(const char *const log_text, ...)
+{
+ if (settings.disableLoggingInGame)
+ return;
+
+ unsigned size = 1024;
+ if (strlen(log_text) * 3 > size)
+ size = CAST_U32(strlen(log_text) * 3);
+
+ char* buf = new char[CAST_SIZE(size + 1)];
+ va_list ap;
+
+ // Use a temporary buffer to fill in the variables
+ va_start(ap, log_text);
+ vsnprintf(buf, size, log_text, ap);
+ buf[size] = 0;
+ va_end(ap);
+
+ // Get the current system time
+ timeval tv;
+ gettimeofday(&tv, nullptr);
+
+ // Print the log entry
+ std::stringstream timeStr;
+ DATESTREAM
+ SPECIALLOG(buf)
+
+ if (mLogFile.is_open())
+ mLogFile << timeStr.str() << buf << std::endl;
+
+ if (mLogToStandardOut)
+ std::cout << timeStr.str() << buf << std::endl;
+
+ DebugMessageListener::distributeEvent(buf);
+
+ // Delete temporary buffer
+ delete [] buf;
+}
+
void Logger::log_r(const char *const log_text, ...)
{
if (settings.disableLoggingInGame)