From 244991dee7a2e274cb361f5040dd39b0f2997290 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 30 Apr 2016 02:03:32 +0300 Subject: Extend assert reporting functions with condition text and call stack. --- src/logger.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/logger.cpp') 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) -- cgit v1.2.3-70-g09d2