Skip to content

Commit

Permalink
Rotate record file before writing new log. (sonic-net#3158)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mint570 authored Jun 4, 2024
1 parent 80f5207 commit fff544e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down

0 comments on commit fff544e

Please sign in to comment.