From 820c5db5e8084322397d638e18dc27bcac99d615 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 9 May 2022 09:58:43 +0200 Subject: [PATCH] Log: check for logrotate only once per loop --- src/log.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/log.cpp b/src/log.cpp index 45756d4..402d69f 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -194,15 +194,6 @@ private: fwrite(p, 1, size, (severity == 1) ? stdout : stderr); #endif - // Reopen the log file if it's been moved (logrotate support) - if (m_logFile.is_open()) { - struct stat buf; - if (stat(log_file_name, &buf) != 0) { - m_logFile.close(); - m_logFile.open(log_file_name, std::ios::app | std::ios::binary); - } - } - if (m_logFile.is_open()) { if (c) { strip_colors(p, size); @@ -232,6 +223,13 @@ private: // Flush the log file only after all pending log lines have been written if (m_logFile.is_open()) { m_logFile.flush(); + + // Reopen the log file if it's been moved (logrotate support) + struct stat buf; + if (stat(log_file_name, &buf) != 0) { + m_logFile.close(); + m_logFile.open(log_file_name, std::ios::app | std::ios::binary); + } } } while (!stopped); }