Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

parameter for log4perl

by fionbarr (Pilgrim)
on Jun 12, 2012 at 12:43 UTC ( #975768=perlquestion: print w/ replies, xml ) Need Help??
fionbarr has asked for the wisdom of the Perl Monks concerning the following question:

I want to keep using a log file until its size>15m. Right now the existing parameters create a new log file each time my program starts...what do I put in the config file to tell it to use the same file until the size is greater than the max?
log4perl.category.fileLogger=INFO, LOGFILE # write to rotating log file log4perl.appender.LOGFILE=Log::Dispatch::FileRotate # log settings log4perl.appender.LOGFILE.filename=/home/user/xxx/review/code_ +review.log log4perl.appender.LOGFILE.size=15M log4perl.appender.LOGFILE.max=15 log4perl.appender.LOGFILE.mode=append # log file format; see http://search.cpan.org/~mschilli/Log-Log4perl-1 +.35/lib/Log/Log4perl.pm#Log_Layouts log4perl.appender.LOGFILE.layout=PatternLayout log4perl.appender.LOGFILE.layout.ConversionPattern=[%d (%P) %rms %p] % +m%n log4perl.appender.LOGFILE.layout.ConversionPattern=[%d] %p %m%n

Comment on parameter for log4perl
Download Code
Re: parameter for log4perl
by chrestomanci (Priest) on Jun 12, 2012 at 12:51 UTC

    Use Log::Dispatch::FileRotate

    If you don't supply a date pattern for log rotation, it will rotate by file size instead, so when the log file reaches 10 Meg (or whatever size you specify) it will rotate the log file & start a new one.

Re: parameter for log4perl
by Khen1950fx (Canon) on Jun 12, 2012 at 14:31 UTC
    I would cleanup a bit:
    #!/usr/bin/perl -l use strict; use warnings; use Log::Dispatch::FileRotate; use Log::Log4perl qw(get_logger); my $conf = q( log4perl.category.fileLogger = INFO, Logfile log4perl.appender.Logfile = Log::Dispatch::FileRotate log4perl.appender.Logfile.filename = code_review.log log4perl.appender.Logfile.mode = append log4perl.appender.Logfile.max = 15 log4perl.appender.Logfile.size = 15000 log4perl.appender.Logfile.layout = \ Log::Log4perl::Layout::PatternLayout log4perl.appender.Logfile.layout.ConversionPattern = \ [%d (%P) %rms %p] %m%n ); Log::Log4perl->init( \$conf );
      thanks to both

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://975768]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-09-21 08:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (167 votes), past polls