chore: Reduce complexity of outputLoop in Windows watchdog
This commit is contained in:
parent
98aba612c0
commit
0f11b61576
1 changed files with 23 additions and 12 deletions
|
|
@ -285,6 +285,28 @@ void MSWindowsWatchdog::setProcessConfig(const std::string_view &command, bool e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string trimOutputBuffer(const CHAR *buffer)
|
||||||
|
{
|
||||||
|
// strip out windows \r chars to prevent extra lines in log file.
|
||||||
|
std::string output(buffer);
|
||||||
|
if (output.empty()) {
|
||||||
|
LOG_DEBUG1("output buffer is empty");
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
void MSWindowsWatchdog::outputLoop(void *)
|
void MSWindowsWatchdog::outputLoop(void *)
|
||||||
{
|
{
|
||||||
const auto kOutputBufferSize = 4096;
|
const auto kOutputBufferSize = 4096;
|
||||||
|
|
@ -304,18 +326,7 @@ void MSWindowsWatchdog::outputLoop(void *)
|
||||||
buffer[bytesRead] = '\0';
|
buffer[bytesRead] = '\0';
|
||||||
|
|
||||||
// strip out windows \r chars to prevent extra lines in log file.
|
// strip out windows \r chars to prevent extra lines in log file.
|
||||||
std::string output(buffer);
|
std::string output = trimOutputBuffer(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 != nullptr) {
|
if (m_fileLogOutputter != nullptr) {
|
||||||
m_fileLogOutputter->write(kPRINT, output.c_str());
|
m_fileLogOutputter->write(kPRINT, output.c_str());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue