From fff544e6b4a5f5a8b9cd901b50c26509e6e69389 Mon Sep 17 00:00:00 2001 From: mint570 <70396898+mint570@users.noreply.github.com> Date: Tue, 4 Jun 2024 14:36:39 -0700 Subject: [PATCH] Rotate record file before writing new log. (#3158) What I did Rotate file before writing the log for record files. Why I did it If we configure logrotate to compress, the old file stream will write to void after the old file is rotated and compressed. This PR changes the order of write and rotate. It will always rotate first and then write. There might still be log lost if logrotate sends HUP signal too late. --- lib/recorder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/recorder.cpp b/lib/recorder.cpp index 449039adff..e9af745cdf 100644 --- a/lib/recorder.cpp +++ b/lib/recorder.cpp @@ -93,12 +93,12 @@ void RecWriter::record(const std::string& val) { return ; } - record_ofs << swss::getTimestamp() << "|" << val << std::endl; if (isRotate()) { setRotate(false); logfileReopen(); } + record_ofs << swss::getTimestamp() << "|" << val << std::endl; }