Skip to content

[$25 BOUNTY] [C] Add frailbox logger rotation retention report#23

Open
leo202000 wants to merge 2 commits into
Soengkit:mainfrom
leo202000:feat/frailbox-logger-retention
Open

[$25 BOUNTY] [C] Add frailbox logger rotation retention report#23
leo202000 wants to merge 2 commits into
Soengkit:mainfrom
leo202000:feat/frailbox-logger-retention

Conversation

@leo202000

Copy link
Copy Markdown

Summary

Adds an audit-friendly retention report for frailbox logger rotation decisions, as requested in issue #3.

Changes

  • frailbox/include/logger.h: New rotation retention report API:

    • log_rotation_report() — scans *.log files in a directory and produces retain/prune decisions based on max_files, max_age_secs, and max_total_bytes policies.
    • log_rotation_report_to_json() / log_rotation_report_to_text() — formatters with ISO-8601 mtime timestamps.
    • log_rotation_report_free() — cleanup.
    • Only file metadata is accessed (name, size, mtime); raw log content is never read or exposed.
  • frailbox/src/logger.c: Implementation of the retention report. Policies applied in order: age → count → total size (oldest pruned first). Entries sorted newest-first.

  • frailbox/tests/test_rotation.c (new): 30 tests covering:

    • max_files policy (retain 2 newest, prune 3 oldest)
    • max_age policy (prune files older than threshold)
    • Combined age + count policy
    • No-limits (all retained)
    • JSON/text output format validation
    • Secret-leak prevention (verifies JSON/text never contains raw log content)
    • NULL and error handling
    • JSON field completeness (filename, size, mtime, decision, reason)
  • frailbox/Makefile: Added test_rotation target.

  • docs/OPERATIONS.md: Documented retention report usage, policies, and JSON format.

Testing

  • make test_rotation — 30 tests, all pass (WSL Ubuntu, gcc 13.3.0)
  • python3 build.py — diagnostic build log generated and included below
    • Build results: frontend PASS, frailbox PASS, engine PASS (3/10 modules; 7 FAIL due to missing toolchains: cargo/go/javac/ruby/luac/ghc)

Checklist

  • Relevant modules affected by these changes build locally
  • Tests pass locally
  • Diagnostic build log is committed in this PR (diagnostic/build-c68dc00f.logd)
  • Changes are scoped to the PR purpose and avoid unrelated cleanup
  • Security, privacy, and error-handling implications have been considered

Closes #3

- Add log_rotation_report() API to logger.h: scans *.log files in a
  directory and produces a retention report with retain/prune decisions
  based on max_files, max_age_secs, and max_total_bytes policies.
- Report entries include filename, size, mtime, decision, and reason.
  Only file metadata is accessed; raw log content is never read or
  exposed (verified by tests checking JSON/text output for secrets).
- Add log_rotation_report_to_json() and log_rotation_report_to_text()
  formatters. JSON includes ISO-8601 mtime timestamps.
- Add log_rotation_report_free() for cleanup.
- Existing logger behavior remains compatible by default (new API is
  opt-in; no changes to existing log_init/log_message/log_shutdown).
- Add frailbox/tests/test_rotation.c: 30 tests covering max_files,
  max_age, combined policies, no-limits, NULL/error handling, JSON
  field validation, and secret-leak prevention.
- Add test_rotation target to Makefile.
- Document retention report usage in docs/OPERATIONS.md.

Closes #3
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.

Payout tracking for upstream PR #396

1 participant