Engine exited successfully on " << currentDate; *m_MainLog << L" at " << currentTime << buffer << L"
\n"; *m_MainLog << html_footer; *m_InterestingLog << L"Engine exited successfully on " << currentDate; *m_InterestingLog << L" at " << currentTime << buffer << L"
\n"; *m_InterestingLog << html_footer; if (m_OwnsStreams) { SAFE_DELETE(m_InterestingLog); SAFE_DELETE(m_MainLog); } } void CLogger::WriteMessage(const wchar_t* message) { ++m_NumberOfMessages; *m_MainLog << L"" << message << L"
\n"; m_MainLog->flush(); } void CLogger::WriteError(const wchar_t* message) { ++m_NumberOfErrors; if (m_UseDebugPrintf) debug_printf(L"ERROR: %ls\n", message); if (g_Console) g_Console->InsertMessage(L"ERROR: %ls", message); *m_InterestingLog << L"ERROR: "<< message << L"
\n"; m_InterestingLog->flush(); *m_MainLog << L"ERROR: "<< message << L"
\n"; m_MainLog->flush(); } void CLogger::WriteWarning(const wchar_t* message) { ++m_NumberOfWarnings; if (m_UseDebugPrintf) debug_printf(L"WARNING: %ls\n", message); if (g_Console) g_Console->InsertMessage(L"WARNING: %ls", message); *m_InterestingLog << L"WARNING: "<< message << L"
\n"; m_InterestingLog->flush(); *m_MainLog << L"WARNING: "<< message << L"
\n"; m_MainLog->flush(); } // Sends the message to the appropriate piece of code // -- This function has not been removed because the build would break. void CLogger::LogUsingMethod(ELogMethod method, const wchar_t* message) { if(method == Normal) WriteMessage(message); else if(method == Error) WriteError(message); else if(method == Warning) WriteWarning(message); else WriteMessage(message); } // -- This function has not been removed because the build would break. void CLogger::Log(ELogMethod method, const wchar_t* UNUSED(category), const wchar_t* fmt, ...) { va_list argp; wchar_t buffer[512]; va_start(argp, fmt); if (sys_vswprintf(buffer, ARRAY_SIZE(buffer), fmt, argp) == -1) { // Buffer too small - ensure the string is nicely terminated wcscpy_s(buffer+ARRAY_SIZE(buffer)-4, 4, L"..."); } va_end(argp); LogUsingMethod(method, buffer); } // -- This function has not been removed because the build would break. void CLogger::LogOnce(ELogMethod method, const wchar_t* UNUSED(category), const wchar_t* fmt, ...) { va_list argp; wchar_t buffer[512]; va_start(argp, fmt); if (sys_vswprintf(buffer, ARRAY_SIZE(buffer), fmt, argp) == -1) { // Buffer too small - ensure the string is nicely terminated wcscpy_s(buffer+ARRAY_SIZE(buffer)-4, 4, L"..."); } va_end(argp); std::wstring message(buffer); // If this message has already been logged, ignore it if (m_LoggedOnce.find(message) != m_LoggedOnce.end()) return; // If not, mark it as having been logged and then log it m_LoggedOnce.insert(message); LogUsingMethod(method, buffer); } void CLogger::LogMessage(const wchar_t* fmt, ...) { va_list argp; wchar_t buffer[512]; va_start(argp, fmt); if (sys_vswprintf(buffer, ARRAY_SIZE(buffer), fmt, argp) == -1) { // Buffer too small - ensure the string is nicely terminated wcscpy_s(buffer+ARRAY_SIZE(buffer)-4, 4, L"..."); } va_end(argp); WriteMessage(buffer); } void CLogger::LogWarning(const wchar_t* fmt, ...) { va_list argp; wchar_t buffer[512]; va_start(argp, fmt); if (sys_vswprintf(buffer, ARRAY_SIZE(buffer), fmt, argp) == -1) { // Buffer too small - ensure the string is nicely terminated wcscpy_s(buffer+ARRAY_SIZE(buffer)-4, 4, L"..."); } va_end(argp); WriteWarning(buffer); } void CLogger::LogError(const wchar_t* fmt, ...) { va_list argp; wchar_t buffer[512]; va_start(argp, fmt); if (sys_vswprintf(buffer, ARRAY_SIZE(buffer), fmt, argp) == -1) { // Buffer too small - ensure the string is nicely terminated wcscpy_s(buffer+ARRAY_SIZE(buffer)-4, 4, L"..."); } va_end(argp); WriteError(buffer); } TestLogger::TestLogger() { m_OldLogger = g_Logger; g_Logger = new CLogger(&m_Stream, &blackHoleStream, false, false); } TestLogger::~TestLogger() { delete g_Logger; g_Logger = m_OldLogger; } std::wstring TestLogger::GetOutput() { return m_Stream.str(); }