The doc seems pretty clear:
Traefik will close and reopen its log files, assuming they're configured, on receipt of a USR1 signal. This allows the logs to be rotated and processed by an external program, such as
logrotate
.
But what is Traefik really doing? When it receives the signal, it should close the log file to be renamed by log rotate. But how long will it wait before resuming? Is there a timer used? Is it checking if the file is gone? Some AI chatbot even suggests sending a different signal to indicate Traefik can continue logging.
How does it work internally?
Something like this will work reliably?
/path/to/traefik/logs/*.log {
rotate 7 # Keep 7 rotated logs
daily # Rotate log files daily
missingok # Don't complain if the log file is missing
compress # Compress rotated log files
delaycompress # Delay compression until the next rotation
notifempty # Do not rotate the log if it's empty
create 0640 root root # Set permissions for the new log file
sharedscripts # Use shared scripts postrotate and prerotate
postrotate
# Send a USR1 signal to the Traefik container
docker exec <your_traefik_container_name> kill -USR1 1
endscript
}
Along with a crontab
0 0 * * * /usr/sbin/logrotate -f /etc/logrotate.d/traefik-logrotate.conf