Part of series: caddy
Log Rotation in Caddy
Log Rotation in Caddy
Log rotation is the process of automatically archiving and deleting old logs to prevent disk space from filling up. For Caddy, log rotation can be set up using external tools like logrotate, widely used for log rotation on Linux.
Configuring Log Rotation with logrotate
1. Install logrotate (if not already installed)
sudo apt install logrotate
2. Create a Configuration for Caddy
Open or create a configuration file for Caddy in /etc/logrotate.d/caddy
:
sudo nano /etc/logrotate.d/caddy
3. Sample Configuration for Caddy Log Rotation
Insert the following configuration into the file:
/var/log/caddy/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 0640 root root
postrotate
systemctl reload caddy
endscript
}
If you are using a user other than root
, replace it accordingly.
Explanation of the Settings
daily
: Logs will be rotated daily. You can change this toweekly
for weekly rotation.rotate 14
: Retain up to 14 log archives.compress
: Compress archives to save space.delaycompress
: Delay compression until the next rotation.notifempty
: Skip rotation if the log file is empty.create 0640 root root
: Create a new file with 0640 permissions androot
as the owner.postrotate
: After rotation, restart the Caddy service to start writing to a new file.
Checking logrotate Configuration
You can check the logrotate configuration with the following command:
sudo logrotate -d /etc/logrotate.d/caddy
This command performs a test and shows how the rotation will proceed, without making changes.
Manually Running logrotate for Testing
To manually trigger rotation and verify functionality, run:
sudo logrotate -f /etc/logrotate.d/caddy
After these steps, logrotate will automatically rotate Caddy logs according to the specified settings.
- Our community Openode.XYZ OpeNode.xyz
- Aeza VPS (+15% on payment) Aeza.net
- Best EU hosting (+1 month free) Kamatera.com
- VPS hosting - 4vps.su (-10% discount!) 4VPS.su
- TG Channel TG-Channel Neonode.cc