Rotating production.log of Redmine
Applications developed with Ruby on Rails, such as Redmine, keep appending information to log/production.log. To prevent the file from growing and using up disk space, consider rotating the log at regular intervals.
Method 1: Use the Rails logger
If you add a Logger setting to config/additional_environment.rb of Redmine, the log is rotated at a fixed size or at a fixed interval.
For example, with the following setting, the log is rotated every time it reaches 10 MB, and up to 10 generations are kept.
config.logger = Logger.new("log/#{Rails.env}.log", 10, 10240000)
If you specify daily, weekly, or monthly as the second parameter, the log is rotated every day, every week, or every month. The following is an example of daily rotation.
config.logger = Logger.new("log/#{Rails.env}.log", 'daily')
You can check the parameters for Logger.new in the reference manual of the Ruby Logger class.
https://docs.ruby-lang.org/en/3.4/Logger.html#method-c-new
Method 2: Use logrotate on Linux
If you run Redmine on Linux, you can use logrotate for this task.
Create a file with the following content under /etc/logrotate.d/. On Red Hat family distributions such as CentOS, the log is then rotated early on Sunday morning.
Example of a logrotate configuration
(when the Redmine installation directory is /var/lib/redmine)
/var/lib/redmine/log/*log {
missingok # Do not report an error if the file does not exist
notifempty #
copytruncate # Copy the log under another name, and then empty the original file
compress # Compress and keep old logs
}
Configuration options of logrotate
Rotation method
| copytruncate | Copy the log, and then empty the original file |
| create mode owner group | Rename the log, and then create a new log file |
Rotation interval
| daily | Every day |
| weekly | Every week |
| monthly | Every month |
