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?

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 (normally this file would be found in /etc/logrotate.d/jenkins or etc/logrotate.d/jenkins-oc):

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

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.

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

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.