class Logging::Appenders::RollingFile

An appender that writes to a file and ensures that the file size or age never exceeds some user specified level.

The goal of this class is to write log messages to a file. When the file age or size exceeds a given limit then the log file is copied and then truncated. The name of the copy indicates it is an older log file.

The name of the log file is changed by inserting the age of the log file (as a single number) between the log file name and the extension. If the file has no extension then the number is appended to the filename. Here is a simple example:

/var/log/ruby.log   =>   /var/log/ruby.1.log

New log messages will continue to be appended to the same log file (‘/var/log/ruby.log` in our example above). The age number for all older log files is incremented when the log file is rolled. The number of older log files to keep can be given, otherwise all the log files are kept.

The actual process of rolling all the log file names can be expensive if there are many, many older log files to process.

If you do not wish to use numbered files when rolling, you can specify the :roll_by option as ‘date’. This will use a date/time stamp to differentiate the older files from one another. If you configure your rolling file appender to roll daily and ignore the file size:

/var/log/ruby.log   =>   /var/log/ruby.20091225.log

Where the date is expressed as ‘%Y%m%d` in the Time#strftime format.

NOTE: this class is not safe to use when log messages are written to files on NFS mounts or other remote file system. It should only be used for log files on the local file system. The exception to this is when a single process is writing to the log file; remote file systems are safe to use in this case but still not recommended.