UPDATE:
The problem was caused by the version of Log-Dispatch-FileRotate I was using. Version 1.11 does not rotate files as expected. The more recent 1.19 version does not have that problem. (When I originally started working with Log-Dispatch-FileRotate it was not available on ActiveState's PPM repository, so I downloaded and installed it from Log4perl's SourceForge repository.)



Good morning!

I am writing a script that writes to log files that are rotated every day (maximum of 8). I am using Log::Log4perl and Log::Dispatch::FileRotate and I am running into some problems (or possibly misunderstandings?).

I am attempting to rotate the log files everyday with a date pattern string of yyyy-MM-dd. This works properly for scripts that run continuously longer than a day, but does not appear to work as expected for shorter running scripts (e.g. script starts up at 20:30 2015-01-14, runs for 5 minutes and exits, then runs again at 02:30 2015-01-15; the log file does not get rotated when the script runs on a new day).

Perl info:

perl -v This is perl 5, version 18, subversion 2 (v5.18.2) built for MSWin32-x +64-multi-thread

Module info:

ppm list --no-header --matching Log- --fields name,version Log-Dispatch 2.42 Log-Dispatch-FileRotate 1.11 Log-Log4perl 1.46 Log-Message 0.08 Log-Message-Simple 0.10

Below are two small example programs that rotate the log file every minute.
Runs continuously for a minute+1 second and rotates as expected:

#!/usr/bin/perl use 5.018; use Log::Dispatch::FileRotate; use Log::Log4perl qw/:easy :no_extra_logdie_message/; use strict; use warnings; local $/ = undef; Log::Log4perl::init(\<DATA>); local $| = 1; INFO("LOG 1: Sleep for 61 seconds"); for ( 1 .. 61 ) { print "\b\b$_"; sleep 1; } INFO("LOG 2: Done"); 1; __DATA__ # Layout for logging # [Date] [Priority] [File::Caller] [Line Number] > Message \n layout_pattern = [%d{yyyy-MM-ddTHH:mm:ss}] [%p] [%F{1}::%M] [%L] > %m +%n ## ## LOGGERS ## log4perl.logger = INFO, LogRotate # Logging to file # - Rotates every minute # - Last 8 minutes kept # (Only INFO level priority and higher messages are logged to file) log4perl.appender.LogRotate.layout.ConversionPattern = ${layout_patter +n} log4perl.appender.LogRotate = Log::Dispatch::FileRotate log4perl.appender.LogRotate.filename = Timed_Rotate.log log4perl.appender.LogRotate.layout = Log::Log4perl::Layout::Patte +rnLayout log4perl.appender.LogRotate.max = 8 log4perl.appender.LogRotate.mode = append log4perl.appender.LogRotate.DatePattern = yyyy-MM-dd-HH-MM

Called every minute+1 second and does not rotate the log file as expected:

#!/usr/bin/perl use 5.018; use Log::Dispatch::FileRotate; use Log::Log4perl qw/:easy :no_extra_logdie_message/; use strict; use warnings; local $/ = undef; Log::Log4perl::init(\<DATA>); local $| = 1; INFO("LOG 1: Sleep for 61 seconds"); 1; __DATA__ # Layout for logging # [Date] [Priority] [File::Caller] [Line Number] > Message \n layout_pattern = [%d{yyyy-MM-ddTHH:mm:ss}] [%p] [%F{1}::%M] [%L] > %m +%n ## ## LOGGERS ## log4perl.logger = INFO, LogRotate # Logging to file # - Rotates every minute # - Last 8 minutes kept # (Only INFO level priority and higher messages are logged to file) log4perl.appender.LogRotate.layout.ConversionPattern = ${layout_patter +n} log4perl.appender.LogRotate = Log::Dispatch::FileRotate log4perl.appender.LogRotate.filename = Timed_Rotate.log log4perl.appender.LogRotate.layout = Log::Log4perl::Layout::Patte +rnLayout log4perl.appender.LogRotate.max = 8 log4perl.appender.LogRotate.mode = append # 'log4j' style doesn't work as expected log4perl.appender.LogRotate.DatePattern = yyyy-MM-dd-HH-MM # ... neither does 'Date::Manip' style # log4perl.appender.LogRotate.DatePattern = 0:0:0:0:0:1:0

Called (assuming code was saved in a file called "test.pl")via: perl -E "local $|=1;`test.pl`; for(1..60){print qq|\b\b$_|;sleep 1;} `test.pl`;"

I am not quite sure what is going on here. Did I do something wrong? Do I have a flawed understanding of how Log::Dispatch::FileRotate is suposed to work?

Thank you for your time.


In reply to [SOLVED] Log::Log4perl and Log::Dispatch::FileRotate: Issues rotating log files based on date pattern by ateague

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.