Skip to content

Setting roll_keep to 0 does not disable it #7863

Description

@StroppaFR

Issue Details

Documentation about the roll_keep log rotation option at https://caddyserver.com/docs/caddyfile/directives/log#roll_keep states the following:

roll_keep is how many log files to keep before deleting the oldest ones. Triggers when a new log file is created.
To disable roll_keep, set the value to 0.

But setting the value to 0 in Caddyfile seems to have no effect and keeps a maximum of 10 log files instead. Example Caddyfile to reproduce the issue:

mywebsite:80 {
    log {
        output file /var/log/caddy/mywebsite.log {
            roll_interval 1s
            roll_keep 0
            roll_keep_for 1d
        }
        format json
    }
    respond "OK"
}
# caddy --version
v2.11.4 h1:XKxkMTgNSizEvKG6QHue6cAsFOteU2qA61w2tKkCWi0=
# ls -la /var/log/caddy/ | grep log.gz | wc -l
10

This could be caused by this:

if fw.RollKeep == 0 {
fw.RollKeep = 10
}

Setting the value to -1 instead removes the limit.

Assistance Disclosure

AI not used

If AI was used, describe the extent to which it was used.

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions