How to Rotate Logs Every X Hours in Caddy?

Hi all,

I’m currently running Caddy as a reverse proxy and it’s working great. However, I’d like to rotate the logs every few hours (e.g. every 6 hours) instead of daily or based on size.

I couldn’t find a native option in the Caddy config for time-based log rotation. Is there a built-in way to do this, or would I need to handle it externally (like with logrotate or a custom script)?

Just trying to keep log files short and easy to manage for a system that gets bursts of traffic at specific intervals.

Appreciate any advice!

Jhonn Marie

1 Like

It’s not currently possible to roll based on time. It’s not a great control mechanism. It’s possible you have high traffic for one hour, so you get large log file for that one hour, then get minimal traffic the next hour, so you get a near-empty log file.

3 Likes

Thanks, Mohammed! That’s a solid point about inconsistent log sizes with time-based rotation. I’ll look into handling it externally with something like logrotate instead, really appreciate the clarity! :memo:

2 Likes

You may want to look at copytruncate with logrotate as Caddy doesn’t yet reopen logfiles. See the request at Logging: reopen logs after reload · Issue #5316 · caddyserver/caddy · GitHub

1 Like