From e967944c1eebdc3a60911676041fec93a6f92f97 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Mon, 10 Feb 2025 18:01:26 +0000 Subject: [PATCH] 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. --- src/lib/platform/MSWindowsWatchdog.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib/platform/MSWindowsWatchdog.cpp b/src/lib/platform/MSWindowsWatchdog.cpp index bcf257835..9b55c5daf 100644 --- a/src/lib/platform/MSWindowsWatchdog.cpp +++ b/src/lib/platform/MSWindowsWatchdog.cpp @@ -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 }