Registry Mirror
Skip to content

Conversation

@nschimme

@nschimme nschimme commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Fix AutoLogger log retention to use a robust file timestamp helper and correct log ordering for cleanup strategies.

Enhancements:

  • Introduce a utils::getFileTime helper that selects a reliable timestamp from QFileInfo with a birth-time fallback to last-modified.
  • Update AutoLogger cleanup to sort logs from newest to oldest so size-based deletions remove the oldest logs first.
  • Use the shared file time helper in date-based deletion to avoid misclassifying logs as extremely old on filesystems with invalid birth times.

Tests:

  • Add unit tests that validate getFileTime behavior across epoch, invalid, boundary, and timezone-variant birth times.
  • Add unit tests that cover DeleteDays behavior on various timestamp combinations to ensure only truly old logs are removed.
  • Add unit tests that verify newest-to-oldest sorting and cumulative size thresholds delete the correct subset of logs.
  • Add an integration-style test that exercises utils::getFileTime on a real temporary file to confirm it returns a recent, valid timestamp.

Summary by Sourcery

Fix AutoLogger retention decisions by using reliable file times and preserving newer logs during cleanup.

Bug Fixes:

  • Correct log retention timestamp handling by falling back to last-modified times when birth times are invalid or unavailable.
  • Fix size-based cleanup to retain the newest logs and remove older logs only after the configured limit is exceeded.

Enhancements:

  • Extract log cleanup policies and timestamp selection into a reusable, filesystem-independent module.

Build:

  • Add the log cleanup implementation to the main and test build targets.

Tests:

  • Add unit and integration coverage for file timestamp selection and day- and size-based log cleanup behavior.

nschimme and others added 2 commits September 13, 2026 14:39
Under sandboxed environments like Flatpak (and some filesystems),
QFileInfo::birthTime() reports epoch 0 or is invalid, so every log
looked decades old and the default DeleteDays strategy deleted all of
them on connect. Fall back to lastModified() when the birth time is
missing or before 1980.

Also fix DeleteSize: the cumulative-size loop iterated oldest-first, so
once the limit was reached it deleted the *newest* logs and kept the
oldest. Sort newest-first so recent logs survive.

The selection policy is extracted into log_cleanup::selectLogsToDelete
(src/logger/LogCleanup.*) so it can be unit tested without a
filesystem, and a new TestAutoLogger covers both bugs against the real
implementation.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJWFydUn7wirdvQttfamkA
Prune older logs only once the total exceeds the limit (a total of
exactly N MB is kept), and never delete the newest log, so a single
oversized log cannot wipe out the whole directory.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJWFydUn7wirdvQttfamkA

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @nschimme, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 19 hours and 58 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 13, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR extracts AutoLogger retention decisions into a testable cleanup module, uses a validated birth-time/last-modified fallback, and sorts logs newest-first so date and size policies delete the intended older files. New tests cover timestamp edge cases, retention boundaries, ordering, cumulative size behavior, and real filesystem timestamps.

Sequence diagram for robust log timestamp selection

sequenceDiagram
    participant AutoLogger
    participant QFileInfo
    participant LogCleanup

    AutoLogger->>QFileInfo: birthTime()
    LogCleanup->>LogCleanup: Validate birth timestamp
    alt valid birth time after epoch cutoff
        LogCleanup-->>AutoLogger: birth time
    else invalid or unreliable birth time
        AutoLogger->>QFileInfo: lastModified()
        LogCleanup-->>AutoLogger: last-modified time
    end
Loading

Flow diagram for AutoLogger cleanup selection

flowchart TD
    A[AutoLogger.deleteOldLogs] --> B[QDir entryInfoList]
    B --> C[getFileTime]
    C --> D[selectLogsToDelete]
    D --> E{Cleanup strategy}
    E -->|KeepForever| F[Return no files]
    E -->|DeleteDays| G[Delete logs at or beyond day threshold]
    E -->|DeleteSize| H[Retain newest logs within size limit]
    G --> I[Return selected files]
    H --> I
    I --> J[Remove selected files]
Loading

File-Level Changes

Change Details Files
Extract log retention policy into a reusable, filesystem-independent cleanup module.
  • Added LogFile and Policy models plus a pure selection function.
  • Handled KeepForever, age-based, and size-based deletion strategies with stable ordering and overflow protection.
  • Registered the new cleanup sources in the main and test builds.
src/logger/LogCleanup.cpp
src/logger/LogCleanup.h
src/CMakeLists.txt
Make file timestamp selection resilient to invalid or unusable birth times.
  • Prefer birth time only when valid and later than the 1980 cutoff.
  • Fall back to last-modified time for missing, epoch, or otherwise invalid birth timestamps.
  • Use the helper when constructing cleanup candidates.
src/logger/LogCleanup.cpp
src/logger/LogCleanup.h
src/logger/autologger.cpp
Correct AutoLogger retention ordering and integrate policy-based deletion.
  • Sort candidates newest to oldest before evaluating cleanup policies.
  • Ensure size-based cleanup retains the newest logs and removes older files after the cumulative threshold is exceeded.
  • Preserve deletion accounting and file removal through the existing AutoLogger flow.
src/logger/LogCleanup.cpp
src/logger/autologger.cpp
Add unit and integration coverage for timestamp handling and cleanup decisions.
  • Test timestamp fallback and real temporary-file timestamps.
  • Cover KeepForever and date thresholds, including exact boundary behavior.
  • Verify unsorted inputs, cumulative size limits, oversized newest files, and single-file retention.
tests/TestAutoLogger.cpp
tests/TestAutoLogger.h
tests/CMakeLists.txt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@nschimme
nschimme merged commit 6306cfd into MUME:master Sep 13, 2026
19 checks passed
@codecov

codecov Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.24528% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 27.24%. Comparing base (1bf323f) to head (07c44f8).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/logger/autologger.cpp 0.00% 16 Missing ⚠️
src/logger/LogCleanup.cpp 83.33% 5 Missing ⚠️
tests/TestAutoLogger.cpp 98.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #554      +/-   ##
==========================================
+ Coverage   27.11%   27.24%   +0.13%     
==========================================
  Files         557      559       +2     
  Lines       45812    45893      +81     
  Branches     4876     4879       +3     
==========================================
+ Hits        12421    12505      +84     
+ Misses      33391    33388       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant