From: Dirk V. <dir...@gm...> - 2007-02-15 12:53:45
|
Hi, is there a easy way to give the rotated files a different suffix? Currently a rotated file will be named: example.log -> example.log.1 but i need something like: example.log.YYYYMMDDHH Maybe by defining a callback? I can't find anything in the docs ... Cheers, Dirk |
From: Robert J. <yad...@sn...> - 2007-02-15 19:55:16
|
At 07:53 AM 2/15/2007, Dirk Vleugels wrote: >Hi, > >is there a easy way to give the rotated files a different suffix? >Currently a rotated file will be named: > >example.log -> example.log.1 > >but i need something like: > >example.log.YYYYMMDDHH > >Maybe by defining a callback? I can't find anything in the docs ... Well, Log::Dispatch::FileRotate isn't part of Log::Log4perl, but I can answer anyway :) I took a look at the source code for FileRotate.pm -- and the renaming scheme is hard-coded: sub log_message { #[...] while($idx >= 0) { if($idx <= 0) { warn "$$ rename $name $name.1\n" if $self->{debug}; rename($name, "$name.1"); } else { warn "$$ rename $name.$idx $name.".($idx+1)."\n" if $self->{debug}; rename("$name.$idx", "$name.".($idx+1)); } $idx--; } # [...] Therefore, you need to subclass and override the log_message() method in order to get the name change you want. Do you know how to do that? I'm not an expert, but I've done something similar before with other modules. HTH, Rob -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Robert Jacobson .......................... Flight Ops. Team Solar Dynamics Observatory (SDO) ............. .............. |
From: John O. <joh...@o-...> - 2007-02-15 20:05:43
|
It has this nifty feature built in, no need to write more code - see below.... Robert Jacobson wrote: > At 07:53 AM 2/15/2007, Dirk Vleugels wrote: > >> Hi, >> >> is there a easy way to give the rotated files a different suffix? >> Currently a rotated file will be named: >> >> example.log -> example.log.1 >> >> but i need something like: >> >> example.log.YYYYMMDDHH >> >> Maybe by defining a callback? I can't find anything in the docs ... >> > > Therefore, you need to subclass and override the log_message() method in order to get the name change you want. Do you know how to do that? I'm not an expert, but I've done something similar before with other modules. > From my log4perl.conf file: log4perl.logger.DataSite = DEBUG, DebugLog log4perl.appender.DebugLog = Log::Dispatch::FileRotate log4perl.appender.DebugLog.min_level=debug log4perl.appender.DebugLog.max=10 log4perl.appender.DebugLog.DatePattern=yyyy-MM-dd log4perl.appender.DebugLog.TZ=UTC log4perl.appender.DebugLog.filename=/tmp/debug_log log4perl.appender.DebugLog.mode=append log4perl.appender.DebugLog.layout=PatternLayout log4perl.appender.DebugLog.layout.ConversionPattern =[%d] [%P] %M(%p) - %m%n The bit you want is DatePattern - it sets the pattern for the rotated files - in your case: DatePattern=yyyyMMdd When the evaluated version of that changes, it will do the rename and start a new file. cheers John |
From: Robert J. <yad...@sn...> - 2007-02-15 21:09:58
|
At 03:06 PM 2/15/2007, John ORourke wrote: >It has this nifty feature built in, no need to write more code - see below.... >[snip] > > >From my log4perl.conf file: > >log4perl.logger.DataSite = DEBUG, DebugLog >log4perl.appender.DebugLog = Log::Dispatch::FileRotate >log4perl.appender.DebugLog.min_level=debug >log4perl.appender.DebugLog.max=10 >log4perl.appender.DebugLog.DatePattern=yyyy-MM-dd >log4perl.appender.DebugLog.TZ=UTC >log4perl.appender.DebugLog.filename=/tmp/debug_log >log4perl.appender.DebugLog.mode=append >log4perl.appender.DebugLog.layout=PatternLayout >log4perl.appender.DebugLog.layout.ConversionPattern =[%d] [%P] %M(%p) - %m%n > > > >The bit you want is DatePattern - it sets the pattern for the >rotated files - in your case: > >DatePattern=yyyyMMdd > >When the evaluated version of that changes, it will do the rename >and start a new file. Are you sure? The documentation for the module says this: "We don't use DatePattern to define the extension of the log file though." The DatePattern seems to define *when to rotate*, and does not affect the file extension. Are you saying you have FileRotate working so that it renames using the DatePattern? Neither the docs nor the code (which I posted earlier) seem to support that... Rob |