Break diags log rotation into subroutines#13254
Conversation
This change reduces a small amount of duplication and introduces meaningful function names. I'm cleaning this up now because there are bugs in the log rotation logic (I have not filed issues yet), and my hope is that this refactoring makes the code easier to understand and review for those bugfixes. * Extract `Diags::roll_diags_on_filesize` * Extract `Diags::roll_diags_on_interval` * Extract `Diags::roll_streams_on_filesize` * Extract `Diags::roll_streams_on_interval` * Extract `Diags::remake_logfile` * Extract `Diags::swap_diagslog`
| // rotate according to the (same || different) scheme, it would not be difficult to add | ||
| // some more config options in records.yaml and said feature into this function. | ||
| if (ret_val) { | ||
| ink_assert(!need_consider_stderr); |
There was a problem hiding this comment.
Instead of asserting that this flag was set, I am asserting at an earlier point that the condition for setting the flag is met. The code was originally designed to be a little easier to change if more output stream flexibility was needed. Since that obviously hasn't happened for a long time, and was only a small amount of code, I have removed the extra logic flow and this flag entirely, simplifying the code.
There was a problem hiding this comment.
Pull request overview
This PR refactors diagnostic and output log rotation in Diags by extracting the previously inlined rotation logic into named helper subroutines, aiming to reduce duplication and make upcoming bugfixes easier to review.
Changes:
- Extracted size-based and time-based rotation logic for
diags.logintoroll_diags_on_filesize()/roll_diags_on_interval(). - Extracted size-based and time-based rotation logic for stdout/stderr output logs into
roll_streams_on_filesize()/roll_streams_on_interval(). - Centralized logfile recreation / swapping logic via
remake_logfile()andswap_diagslog(), usingstd::unique_ptrfor safer ownership.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/tscore/Diags.cc |
Refactors log rotation and reseating logic into helpers; introduces unique_ptr management and guard-clause flow. |
include/tscore/DiagsTypes.h |
Declares the newly extracted private helper methods on Diags. |
* Include `<stdexcept>` for `std::runtime_error` * Make catch statements consistent * Assert stdout/stderr filename invariant in release builds
This change reduces a small amount of duplication and introduces meaningful function names. I'm cleaning this up now because there are (very minor) bugs in the log rotation logic (I have not filed issues yet), and my hope is that this refactoring makes the code easier to understand and review for those bugfixes.
This change restructures conditional flow to use guard clauses instead of nesting all the logic in conditional checks.
Extract
Diags::roll_diags_on_filesizeExtract
Diags::roll_diags_on_intervalExtract
Diags::roll_streams_on_filesizeExtract
Diags::roll_streams_on_intervalExtract
Diags::remake_logfileExtract
Diags::swap_diagslog