On Mon, 24 Aug 2009, Ronald Fischer wrote:

> Is there an easy way to limit the size of a log file? I'm not looking
> for a rollover solution, but for one, where a new file is created if
> the old one exceeds a certain size.

That's pretty much the case with Log::Dispatch::FileRotate, a given file
size, and a max value of 1. If somefile.log grows larger than 'size'
bytes, it'll move it over to somefile.log.1 and moves it over to
somefile.log. Alternatively, you can use an external rotator with
similar settings.

If you don't want to roll over, but truncate the logfile in this case
(although this seems weird, as you might end up with an almost-empty
logfile at times), you need to write your own appender as outlined in

     
http://search.cpan.org/dist/Log-Log4perl/lib/Log/Log4perl/FAQ.pm#How_can_I_write_my_own_appender?

> My idea is to intercept each call to Log4perl, test the size of the
> log file, and switch to a new log file if the old one got too big.

That's exactly what Log::Dispatch::FileRotate does if you call it with
a max value of 1.

-- Mike

Mike Schilli
m...@perlmeister.com

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel

Reply via email to