mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 19:49:19 +02:00
Logging tweaks
This commit is contained in:
37
Logs.cpp
37
Logs.cpp
@@ -23,6 +23,8 @@ char logbuffer[ 256 ];
|
|||||||
|
|
||||||
char endstring[10] = "\n";
|
char endstring[10] = "\n";
|
||||||
|
|
||||||
|
std::mutex logMutex;
|
||||||
|
|
||||||
std::deque<std::string> log_scrollback;
|
std::deque<std::string> log_scrollback;
|
||||||
|
|
||||||
std::string filename_date() {
|
std::string filename_date() {
|
||||||
@@ -76,37 +78,35 @@ std::deque<char *> ErrorStack;
|
|||||||
|
|
||||||
void LogService()
|
void LogService()
|
||||||
{
|
{
|
||||||
while (true)
|
while (!Global.applicationQuitOrder)
|
||||||
{
|
{
|
||||||
if (InfoStack.empty() && ErrorStack.empty() && Global.applicationQuitOrder)
|
{
|
||||||
break;
|
std::lock_guard<std::mutex> lock(logMutex);
|
||||||
// loop for logging
|
|
||||||
|
|
||||||
// write logs and log.txt
|
// --- Obsługa InfoStack ---
|
||||||
while (!InfoStack.empty())
|
while (!InfoStack.empty())
|
||||||
{
|
{
|
||||||
char *msg = InfoStack.front(); // get first element of stack
|
char *msg = InfoStack.front();
|
||||||
InfoStack.pop_front();
|
InfoStack.pop_front();
|
||||||
|
|
||||||
if (Global.iWriteLogEnabled & 1)
|
if (Global.iWriteLogEnabled & 1)
|
||||||
{
|
{
|
||||||
if (!output.is_open())
|
if (!output.is_open())
|
||||||
{
|
{
|
||||||
|
std::string filename = (Global.MultipleLogs ? "logs/log (" + filename_scenery() + ") " + filename_date() + ".txt" : "log.txt");
|
||||||
std::string const filename = (Global.MultipleLogs ? "logs/log (" + filename_scenery() + ") " + filename_date() + ".txt" : "log.txt");
|
|
||||||
output.open(filename, std::ios::trunc);
|
output.open(filename, std::ios::trunc);
|
||||||
}
|
}
|
||||||
output << msg << "\n";
|
output << msg << "\n";
|
||||||
output.flush();
|
output.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
log_scrollback.emplace_back(std::string(msg));
|
log_scrollback.emplace_back(msg);
|
||||||
if (log_scrollback.size() > 200)
|
if (log_scrollback.size() > 200)
|
||||||
log_scrollback.pop_front();
|
log_scrollback.pop_front();
|
||||||
|
|
||||||
if (Global.iWriteLogEnabled & 2)
|
if (Global.iWriteLogEnabled & 2)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// hunter-271211: pisanie do konsoli tylko, gdy nie jest ukrywana
|
|
||||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);
|
||||||
DWORD wr = 0;
|
DWORD wr = 0;
|
||||||
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), msg, (DWORD)strlen(msg), &wr, NULL);
|
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), msg, (DWORD)strlen(msg), &wr, NULL);
|
||||||
@@ -115,29 +115,36 @@ void LogService()
|
|||||||
printf("%s\n", msg);
|
printf("%s\n", msg);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(msg); // cleanup po strdup
|
||||||
}
|
}
|
||||||
|
|
||||||
// write to errors.txt
|
// --- Obsługa ErrorStack ---
|
||||||
while (!ErrorStack.empty())
|
while (!ErrorStack.empty())
|
||||||
{
|
{
|
||||||
char *msg = ErrorStack.front();
|
char *msg = ErrorStack.front();
|
||||||
ErrorStack.pop_front();
|
ErrorStack.pop_front();
|
||||||
|
|
||||||
if (!(Global.iWriteLogEnabled & 1))
|
if (!(Global.iWriteLogEnabled & 1))
|
||||||
return;
|
{
|
||||||
|
free(msg);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!errors.is_open())
|
if (!errors.is_open())
|
||||||
{
|
{
|
||||||
|
std::string filename = (Global.MultipleLogs ? "logs/errors (" + filename_scenery() + ") " + filename_date() + ".txt" : "errors.txt");
|
||||||
std::string const filename = (Global.MultipleLogs ? "logs/errors (" + filename_scenery() + ") " + filename_date() + ".txt" : "errors.txt");
|
|
||||||
errors.open(filename, std::ios::trunc);
|
errors.open(filename, std::ios::trunc);
|
||||||
errors << "EU07.EXE " + Global.asVersion << "\n";
|
errors << "EU07.EXE " + Global.asVersion << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
errors << msg << "\n";
|
errors << msg << "\n";
|
||||||
errors.flush();
|
errors.flush();
|
||||||
|
free(msg); // cleanup po strdup
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(5)); // dont burn cpu so much
|
}
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user