Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/CLogger.cpp
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | static std::string ToHTML(const char* message) | ||||
boost::algorithm::replace_all(cmessage, "<", "<"); | boost::algorithm::replace_all(cmessage, "<", "<"); | ||||
return cmessage; | return cmessage; | ||||
} | } | ||||
void CLogger::WriteMessage(const char* message, bool doRender = false) | void CLogger::WriteMessage(const char* message, bool doRender = false) | ||||
{ | { | ||||
std::string cmessage = ToHTML(message); | std::string cmessage = ToHTML(message); | ||||
CScopeLock lock(m_Mutex); | std::lock_guard<std::mutex> lock(m_Mutex); | ||||
++m_NumberOfMessages; | ++m_NumberOfMessages; | ||||
// if (m_UseDebugPrintf) | // if (m_UseDebugPrintf) | ||||
// debug_printf("MESSAGE: %s\n", message); | // debug_printf("MESSAGE: %s\n", message); | ||||
*m_MainLog << "<p>" << cmessage << "</p>\n"; | *m_MainLog << "<p>" << cmessage << "</p>\n"; | ||||
m_MainLog->flush(); | m_MainLog->flush(); | ||||
if (doRender) | if (doRender) | ||||
{ | { | ||||
if (g_Console) g_Console->InsertMessage(std::string("INFO: ") + message); | if (g_Console) g_Console->InsertMessage(std::string("INFO: ") + message); | ||||
PushRenderMessage(Normal, message); | PushRenderMessage(Normal, message); | ||||
} | } | ||||
} | } | ||||
void CLogger::WriteError(const char* message) | void CLogger::WriteError(const char* message) | ||||
{ | { | ||||
std::string cmessage = ToHTML(message); | std::string cmessage = ToHTML(message); | ||||
CScopeLock lock(m_Mutex); | std::lock_guard<std::mutex> lock(m_Mutex); | ||||
++m_NumberOfErrors; | ++m_NumberOfErrors; | ||||
if (m_UseDebugPrintf) | if (m_UseDebugPrintf) | ||||
debug_printf("ERROR: %.16000s\n", message); | debug_printf("ERROR: %.16000s\n", message); | ||||
if (g_Console) g_Console->InsertMessage(std::string("ERROR: ") + message); | if (g_Console) g_Console->InsertMessage(std::string("ERROR: ") + message); | ||||
*m_InterestingLog << "<p class=\"error\">ERROR: " << cmessage << "</p>\n"; | *m_InterestingLog << "<p class=\"error\">ERROR: " << cmessage << "</p>\n"; | ||||
m_InterestingLog->flush(); | m_InterestingLog->flush(); | ||||
*m_MainLog << "<p class=\"error\">ERROR: " << cmessage << "</p>\n"; | *m_MainLog << "<p class=\"error\">ERROR: " << cmessage << "</p>\n"; | ||||
m_MainLog->flush(); | m_MainLog->flush(); | ||||
PushRenderMessage(Error, message); | PushRenderMessage(Error, message); | ||||
} | } | ||||
void CLogger::WriteWarning(const char* message) | void CLogger::WriteWarning(const char* message) | ||||
{ | { | ||||
std::string cmessage = ToHTML(message); | std::string cmessage = ToHTML(message); | ||||
CScopeLock lock(m_Mutex); | std::lock_guard<std::mutex> lock(m_Mutex); | ||||
++m_NumberOfWarnings; | ++m_NumberOfWarnings; | ||||
if (m_UseDebugPrintf) | if (m_UseDebugPrintf) | ||||
debug_printf("WARNING: %s\n", message); | debug_printf("WARNING: %s\n", message); | ||||
if (g_Console) g_Console->InsertMessage(std::string("WARNING: ") + message); | if (g_Console) g_Console->InsertMessage(std::string("WARNING: ") + message); | ||||
*m_InterestingLog << "<p class=\"warning\">WARNING: " << cmessage << "</p>\n"; | *m_InterestingLog << "<p class=\"warning\">WARNING: " << cmessage << "</p>\n"; | ||||
m_InterestingLog->flush(); | m_InterestingLog->flush(); | ||||
Show All 21 Lines | void CLogger::Render() | ||||
textRenderer.Font(font_name); | textRenderer.Font(font_name); | ||||
textRenderer.Color(1.0f, 1.0f, 1.0f); | textRenderer.Color(1.0f, 1.0f, 1.0f); | ||||
// Offset by an extra 35px vertically to avoid the top bar. | // Offset by an extra 35px vertically to avoid the top bar. | ||||
textRenderer.Translate(4.0f, 35.0f + lineSpacing, 0.0f); | textRenderer.Translate(4.0f, 35.0f + lineSpacing, 0.0f); | ||||
// (Lock must come after loading the CFont, since that might log error messages | // (Lock must come after loading the CFont, since that might log error messages | ||||
// and attempt to lock the mutex recursively which is forbidden) | // and attempt to lock the mutex recursively which is forbidden) | ||||
CScopeLock lock(m_Mutex); | std::lock_guard<std::mutex> lock(m_Mutex); | ||||
for (const RenderedMessage& msg : m_RenderMessages) | for (const RenderedMessage& msg : m_RenderMessages) | ||||
{ | { | ||||
const char* type; | const char* type; | ||||
if (msg.method == Normal) | if (msg.method == Normal) | ||||
{ | { | ||||
type = "info"; | type = "info"; | ||||
textRenderer.Color(0.0f, 0.8f, 0.0f); | textRenderer.Color(0.0f, 0.8f, 0.0f); | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | void CLogger::PushRenderMessage(ELogMethod method, const char* message) | ||||
{ | { | ||||
RenderedMessage r = { method, now, std::string(pos) }; | RenderedMessage r = { method, now, std::string(pos) }; | ||||
m_RenderMessages.push_back(r); | m_RenderMessages.push_back(r); | ||||
} | } | ||||
} | } | ||||
void CLogger::CleanupRenderQueue() | void CLogger::CleanupRenderQueue() | ||||
{ | { | ||||
CScopeLock lock(m_Mutex); | std::lock_guard<std::mutex> lock(m_Mutex); | ||||
if (m_RenderMessages.empty()) | if (m_RenderMessages.empty()) | ||||
return; | return; | ||||
double now = timer_Time(); | double now = timer_Time(); | ||||
// Initialise the timer on the first call (since we can't do it in the ctor) | // Initialise the timer on the first call (since we can't do it in the ctor) | ||||
if (m_RenderLastEraseTime == -1.0) | if (m_RenderLastEraseTime == -1.0) | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator