Read more

How to rotate log files explicitly

Arne Hartherz
April 04, 2013Software engineer at makandra GmbH

Usually, the logrotate service takes care of renaming log files each night or so to avoid logs becoming huge. That will rename your.log to your.log.1, the next time to your.log.2.gz, etc. Here is how to make that happen out of band (you should rarely need to do that).

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Logrotate won't touch all your logs automagically. There is a config file for each service which you can tell logrotate to use.

So if you need logs to be rotated right now, do this (as root):

logrotate --force PATH_TO_CONFIG_FILE

For example, to rotate all your Apache logs (warning: this usually restarts Apache as well):

logrotate --force /etc/logrotate.d/apache2

Remember that an alternative is to use timestamped logs and logrotate might not touch those for you. If you have them, cast some other kind of magic.

Posted by Arne Hartherz to makandra dev (2013-04-04 13:45)