fix: Strip line endings for Windows daemon file logging

Windows file logger and `OutputDebugString` already add new lines, so remove the ones added by the Core.
This commit is contained in:
Nick Bolton
2025-02-10 18:01:26 +00:00
parent 389028ccf9
commit e967944c1e

View File

@ -9,6 +9,7 @@
#include "arch/Arch.h"
#include "arch/win32/XArchWindows.h"
#include "base/ELevel.h"
#include "base/Log.h"
#include "base/TMethodJob.h"
#include "base/log_outputters.h"
@ -408,8 +409,22 @@ void MSWindowsWatchdog::outputLoop(void *)
} else {
buffer[bytesRead] = '\0';
// strip out windows \r chars to prevent extra lines in log file.
std::string output(buffer);
if (!output.empty()) {
size_t pos = 0;
while ((pos = output.find("\r", pos)) != std::string::npos) {
output.replace(pos, 1, "");
}
// trip ending newline, as file writer will add it's own newline.
if (output[output.length() - 1] == '\n') {
output = output.substr(0, output.length() - 1);
}
}
if (m_fileLogOutputter != NULL) {
m_fileLogOutputter->write(kINFO, buffer);
m_fileLogOutputter->write(kPRINT, output.c_str());
}
#if SYSAPI_WIN32
@ -418,7 +433,7 @@ void MSWindowsWatchdog::outputLoop(void *)
// process output to the VS debug output window.
// we could use the MSWindowsDebugOutputter, but it's really fiddly to
// so, and there doesn't seem to be an advantage of doing that.
OutputDebugString(buffer);
OutputDebugString(output.c_str());
}
#endif
}