Log file rotation

Issue

  • The log files in /var/log/jenkins on my Jenkins master are rapidly growing and using up disk space. What is the best way to roll over logs without impacting the Jenkins operations and version upgrades?
  • I need to prevent my Garbage Collection Logs from filling up my disk space

Environment

  • CloudBees Jenkins Operations Center
  • CloudBees Jenkins Enterprise

Resolution

The log file location may vary depending on your system. For most Linux systems, by default the Jenkins Enterprise logs should be in /var/log/jenkins (or /var/log/jenkins-oc for Jenkins Operations Center)

The logrotate utility manages how the log files are rotated and compressed. Type man logrotate at the command-line to see a detailed list of the various options, including some good examples. Or alternatively, this Understanding logrotate Utility article offers a pretty good summary and includes examples.

The logrotate utility includes some frequently used options, such as compression, timeframe, and size of a log before rotation occurs.

If you are not encountering issues with log rotation and sizes, and for most small to medium-sized Jenkins instances - it’s probably best to let logrotate work with it’s default behavior. Here is an example of a configuration which includes good basic settings:

/var/log/jenkins/jenkins.log {
        weekly
        copytruncate
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
}

Normally this file would be found in /etc/logrotate.d/jenkins or etc/logrotate.d/jenkins-oc. If the file does not already exist, create it and populate it with the above example.

If you have a larger Jenkins instance, or if the logs are located on a NAS (perhaps linked to /var/log/jenkins), beware that latency or connection issues between the Jenkins master and the NAS/filesystem may result in logging issues.

Also please ensure the Jenkins administrator is the owner and has the correct read/write permissions to the directory and filesystem.

Garbage Collection Logs

GC logs are enabled per our Best Practices and with the current implementation of Java 8, logs are not deleted. Therefore it is the duty of the Linux Administrator to implement logrotate to ensure that GC logs are removed.

For troubleshooting purposes, 2-3 days of GC logs is enough to diagnose and troubleshoot an issue in most cases.

Related Articles:
* Why is my Jenkins access log empty?
* Changing location of log file

Have more questions?

0 Comments

Please sign in to leave a comment.