vinoth.ree has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!

I am using the Log::Dispatch::FileRotate perl module to genarate log file and rotate the log file based on the configuration, Below is the configuration, but the log file is not getting open in append mode, but I set the mode as 'append' only. In the log file I am getting only the last message what I wrote into it. Please tell me whether the configuration is wrong?

my $file = Log::Dispatch::FileRotate->new(name =>file1', min_level =>'info', filename => "/ree/DB_log.log", mode => 'append', size => 10, max => 5, );

Replies are listed 'Best First'.
Re: Log::Dispatch::FileRotate ?
by nagalenoj (Friar) on Nov 25, 2009 at 08:53 UTC
    Hello ree,

    Append mode is working well. You please change the size parameter and test it again. It'll work fine.

    -- size ($) The maximum (or close to) size the log file can grow too.

      Hi Nagalenoj,

      You are right, when I increase the file size to 1000 it appends the content in the file. I thought that 10 in size field for 10MB, I thing its takes 10KB as file size, but I am not sure. Thanks!

        The documentation is unclear, but if you look at the source, it is very clear that the size is in bytes. The size parameter defaults to 10MB, so try the default.

        Here is the relevant section of code from the Log::Dispatch::FileRotate module's constructor:

        # Size defaults to 10meg in all failure modes, hopefully my $ten_meg = 1024*1024*10; my $two_gig = 1024*1024*1024*2; my $size = $ten_meg; $size = $p{size} if defined $p{size}; $size = $ten_meg unless $size =~ /^\d+$/ && $size < $two_gig && $s +ize > 0; $self->{size} = $size;

      Did you tried the above code? with different size value?

      I changed the size to 5 and 1 no use same thing is happening for me.

        Sorry! The Last reply is mine. ree

Re: Log::Dispatch::FileRotate ?
by Anonymous Monk on Nov 25, 2009 at 08:14 UTC
    The configuration looks ok, so please show a small self-contained example that demonstrates your problem.
      use Log::Dispatch::FileRotate; my $file = Log::Dispatch::FileRotate->new( name => 'file1', min_level => 'info', filename => 'ree.log', mode => 'append', size => 10, max => 5, ); $file->log( level => 'info', message => "Module Testing\n");

      Sample Code using Log::Dispatch::FileRotate module, its print the message into the file not appending its writing the same message in 6 files namely ree.log, ree.log.1,ree.log.2,ree.log.3,ree.log.4,ree.log.5