Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I rotate and compress Log4perl log files?

Tags:

From what I can tell neither Log4Perl or any of its related modules in CPAN supports rotate & compression of log files.

Rotation can be accomplished by using:

  1. Log::Log4perl::Appender::File
  2. Log::Dispatch::FileRotate.

But neither modules supports rotation and compression. (Log::Dispatch::FileRotate has it in its todo list, but it's not currently implemented).

It is possible to do this using the standard Logrotate facility in Linux, by using either Log::Log4perl::Appender::File's recreate_check_interval or recreate_check_signal.

From initial tests, it looks like using Logrotate with the delaycompress option will do the trick - even on a machine with high load, as once the file is moved, log4perl will continue logging to the same filehandle, until the signal is cought.

However, if delaycompress is not used, and there is (even a slight delay) between the compressing of the log file, and the catching the signal by the Perl program, some logging data might be lost.

What do you think? Are there other options we did not think of?