man Log::Agent::Rotate () - parameters for logfile rotation


Log::Agent::Rotate - parameters for logfile rotation


 require Log::Agent::Rotate;

 my $policy = Log::Agent::Rotate->make(
     -backlog     => 7,
     -unzipped    => 2,
     -is_alone    => 0,
     -max_size    => 100_000,
     -max_time    => "1w",
     -file_perm   => 0666


The CWLog::Agent::Rotate class holds the parameters describing the logfile rotation policy, and is meant to be supplied to instances of CWLog::Agent::Driver::File via arguments in the creation routine, such as CW-rotate, or by using array references as values in the CW-channels hashref: See complementary information in Log::Agent::Driver::File.

As rotation cycles are performed, the current logfile is renamed, and possibly compressed, until the maximum backlog is reached, at which time files are deleted. Assuming a backlog of 5 and that the latest 2 files are not compressed, the following files can be present on the filesystem:

    logfile           # the current logfile
    logfile.0         # most recently renamed logfile
    logfile.4.gz      # oldest logfile, unlinked next cycle

The following switches are available to the creation routine make(), listed in alphabetical order, all taking a single integer value as argument:

The total amount of old logfiles to keep, besides the current logfile. Defaults to 7.
The file permissions, given as an octal integer value, to supply to sysopen() during file creation. This value is modified during execution by the umask of the process. In most cases, it is good practice to leave this set to the default and let the user process controll the file permissions. Defaults to 0666.
The argument is a boolean stating whether the program writing to the logfile will be the only one or not. This is a hint that drives some optimizations, but it is up to the program to guarantee that noone else will be able to write to or unlink the current logfile when set to true. Defaults to false.
The maximum logfile size. This is a threshold, which will cause a logfile rotation cycle to be performed, when crossed after a write to the file. If set to CW0, this threshold is not checked. Defaults to 1 megabyte.
The maximum time in seconds between the moment we opened the file and the next rotation cycle occurs. This threshold is only checked after a write to the file. The value can also be given as a string, postfixed by one of the following letters to specify the period unit (e.g. 3w):
    Letter   Unit
    ------   -------
       m     minutes
       h     hours
       d     days
       d     days
       w     weeks
       M     months (30 days of 24 hours)
       y     years
Defaults to CW0, meaning it is not checked.
The maximum amount of data we can write to the logfile. Like CWmax_size, this is a threshold, which is only checked after a write to the logfile. This is not the total logfile size: if several programs write to the same logfile and CWmax_size is not used, then the logfiles may never be rotated at all if none of the programs write at least CWmax_write bytes to the logfile before exiting. Defaults to CW0, meaning it is not checked.
The argument is a boolean stating whether the access to the logfiles will be made from one single host or not. This is a hint that drives some optimizations, but it is up to the program to guarantee that it is accurately set. Defaults to false, which is always a safe value.
The amount of old logfiles, amongst the most recent ones, that should not be compressed but be kept as plain files. Defaults to 1.

To test whether two configurations are strictly identical, use is_same(), as in:

    print "identical\n" if $x->is_same($y);

where both CW$x and CW$y are CWLog::Agent::Rotate objects.

All the aforementioned switches also have a corresponding querying routine that can be issued on instances of the class to get their value. It is not possible to modify those attributes.

For instance:

    my $x = Log::Agent::Rotate->make(...);
    my $mwrite = $x->max_write();

would get the configured max_write threshold.


Originally written by Raphael Manfredi <>, currently maintained by Mark Rogaski <>.

Thanks to Chris Meshkin for his suggestions on file permissions.