Skip to content

Logging: reopen logs after reload #5316

@motiejus

Description

@motiejus

Summary: when Caddy is reloaded, it should re-open its log files. If the file does not exist, create one.

Use case: I would like logrotate to rotate the log files. This is the convention with logrotate services (copied from #329 (comment)). When time to rotate the configs come:

  1. move the log file (e.g. mv access.log access.log.1).
  2. reload the process: systemctl reload caddy.
  3. let the process close the log file. There is no race condition, because the process kept writing to the file with the new name until now.
  4. let the process re-open the log file with old (original) name. This creates a new file.
  5. do something with renamed log file (compress)

However, step (4) does not work: Caddy does not re-open the file.

Steps to reproduce

Caddyfile

{
    http_port 8088
    https_port 8084
}

http://localhost:8088 {
    file_server 

    log {
        output file access.log
    }
}
  1. Run the server: caddy run --config Caddyfile
  2. Issue a request: curl http://localhost:8088
  3. Observe there is a log line in access.log.
  4. mv access.log access.log.1
  5. caddy reload --config Caddyfile --force`
  6. Issue a 2nd request: curl http://localhost:8088
  7. Observe that the logs of the second request are in access.log.1, and access.log was not created.

What did I expect instead?

At step (6) a new file access.log was created and it has the mentioned log line.

Original issue: #329 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions