Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable logrotation for traefik?

Tags:

traefik

How do I enable log rotation for log files e.g. access.log.

Is this built in ?

Docs only say "This allows the logs to be rotated and processed by an external program, such as logrotate"

like image 763
Robert Lachner Avatar asked Mar 23 '18 13:03

Robert Lachner


2 Answers

If you are running Traefik in a Docker container then you can do something like this:

Check that logrotate is installed

logrotate --version

Create file in /etc/logrotate.d/

vi /etc/logrotate.d/traefik

Put the following script, do not forget to fill with the container name.

/var/log/traefik/*.log {
  size 10M
  rotate 5
  missingok
  notifempty
  postrotate
    docker kill --signal="USR1" <container-name>
  endscript
}

Run!

logrotate /etc/logrotate.conf --debug 
logrotate /etc/logrotate.conf
like image 173
Slipstream Avatar answered Nov 09 '22 08:11

Slipstream


Log Rotation

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.

https://docs.traefik.io/v1.6/configuration/logs/#log-rotation

like image 37
ldez Avatar answered Nov 09 '22 07:11

ldez