in reply to Log4perl log rotation in threadpool environment

Maybe you can:

  1. copy the existing log file to a new name
    e.g. copy log_file to log_file.2012-11-16
  2. truncate the log file
  3. Optionally zip the archive file

That way the file handle for the log file doesn't change.

A Monk aims to give answers to those who have none, and to learn from those who know more.
  • Comment on Re: Log4perl log rotation in threadpool environment

Replies are listed 'Best First'.
Re^2: Log4perl log rotation in threadpool environment
by rmahin (Scribe) on Nov 16, 2012 at 18:29 UTC
    Thanks! That was my original idea actually but wasnt aware I could erase (truncate was apparently the word I should have search on) the contents of the file with file handle open. Changed my obnoxious swapping code to
    copy($currFile, $logDir. $self->{old_logs_name}. '.1') or die +"Could not copy the log file because $!"; my $fh = $self->{fh}; truncate($fh, 0) or die "Could not truncate the log file becau +se $!"; seek($fh, 0, 0) or die "Could not set the position in the log +file because $!";
    Thanks again!
      Another satisfied customer :-)
      A Monk aims to give answers to those who have none, and to learn from those who know more.