in reply to Re: Automating File Rotation
in thread Automating File Rotation

I checked that module out but it only increments the name of the logfile as specified by a counter value. I was hoping to rotate mine based on a time value

Replies are listed 'Best First'.
Re^3: Automating File Rotation
by ikegami (Patriarch) on Sep 14, 2004 at 19:22 UTC

    So copy the module, rename it, add use POSIX qw(strftime);, remove

    for($i = $self->{'Count'}; $i > 1; $i--) { $j = $i - 1; $next = "${currn}." . $i . $ext; $prev = "${currn}." . $j . $ext; if ( -r $prev && -f $prev ) { move($prev,$next) ## move will attempt rename for us or croak "error: move failed: ($prev,$next)"; } }

    and change
    $next = "${currn}.1";
    to
    $next = "${currn}_" . strfmt('...', localtime);

    Here's some time formats friendly to Windows and UNIX shells which are string-sortable:

    use POSIX qw(strftime); @t = localtime; $\ = "\n"; print strftime("%Y%m%d%H%M%S", @t); # logfile_20040914151753 print strftime("%Y%m%d-%H%M%S", @t); # logfile_20040914-151753 print strftime("%Y-%m-%d-%H%M%S", @t); # logfile_2004-09-14-151753 print strftime("%Y-%m-%d@%H-%M-%S", @t); # logfile_2004-09-14@15-17-53
Re^3: Automating File Rotation
by Beechbone (Friar) on Sep 15, 2004 at 10:20 UTC