Skip to content

log: support d (day) in roll_interval directive - #7900

Merged
mohammed90 merged 1 commit into
masterfrom
fix-7865
Jul 21, 2026
Merged

mohammed90 merged 1 commit into
masterfrom
fix-7865

Conversation

@mohammed90

Copy link
Copy Markdown
Member

Originally fixed in #7865

roll_interval was using time.ParseDuration which doesn't understand the d (day) unit, causing roll_interval 1d to fail at startup despite Caddy's duration conventions supporting it.

Changes

  • FileWriter.RollInterval: Changed from time.Duration to caddy.Duration — also fixes JSON config support for the d unit
  • UnmarshalCaddyfile: Use caddy.ParseDuration instead of time.ParseDuration for roll_interval parsing
  • OpenWriter: Cast caddy.Duration → time.Duration when passing to timberjack's RotationInterval
  • Tests: Added TestCaddyfile_RollInterval covering 1d, 24h, 30m, 1.5d, and invalid input
log {
    output file /var/log/caddy/access.log {
        roll_interval 1d   # previously failed; now works
    }
}

Assistance Disclosure

Code generated by GitHub Copilot coding agent (claude-sonnet-4.6), reviewed and verified by the operator.

Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes roll_interval parsing for the file log writer to support Caddy’s d (day) duration unit, aligning Caddyfile parsing and JSON config behavior with Caddy’s duration conventions.

Changes:

  • Switched FileWriter.RollInterval from time.Duration to caddy.Duration to support d in JSON config.
  • Updated Caddyfile parsing of roll_interval to use caddy.ParseDuration (supports d) instead of time.ParseDuration.
  • Added Caddyfile parsing tests covering valid day/hour/minute inputs, fractional days, and invalid values.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
modules/logging/filewriter.go Uses caddy.Duration and caddy.ParseDuration so roll_interval 1d works consistently across config formats; casts back to time.Duration when configuring timberjack.
modules/logging/filewriter_test.go Adds a focused Caddyfile parsing test suite for roll_interval, including day and fractional-day cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +711 to +714
gotSecs := time.Duration(fw.RollInterval).Seconds()
if gotSecs != tt.wantSecs {
t.Errorf("got %v seconds, want %v", gotSecs, tt.wantSecs)
}
@mohammed90
mohammed90 merged commit 31daa22 into master Jul 21, 2026
32 of 33 checks passed
@mohammed90
mohammed90 deleted the fix-7865 branch July 21, 2026 22:39
@mohammed90 mohammed90 linked an issue Jul 21, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature ⚙️ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

roll_interval does not support "d" (day) duration

3 participants