.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "FileRotate 3pm" .TH FileRotate 3pm "2023-10-28" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Log::Dispatch::FileRotate \- Log to files that archive/rotate themselves .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Log::Dispatch::FileRotate; \& \& my $file = Log::Dispatch::FileRotate\->new( name => \*(Aqfile1\*(Aq, \& min_level => \*(Aqinfo\*(Aq, \& filename => \*(AqSomefile.log\*(Aq, \& mode => \*(Aqappend\*(Aq , \& size => 10, \& max => 6, \& ); \& # or for a time based rotation \& \& my $file = Log::Dispatch::FileRotate\->new( name => \*(Aqfile1\*(Aq, \& min_level => \*(Aqinfo\*(Aq, \& filename => \*(AqSomefile.log\*(Aq, \& mode => \*(Aqappend\*(Aq , \& TZ => \*(AqAEDT\*(Aq, \& DatePattern => \*(Aqyyyy\-dd\-HH\*(Aq, \& ); \& \& $file\->log( level => \*(Aqinfo\*(Aq, message => "your comment\en" ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides a simple object for logging to files under the Log::Dispatch::* system, and automatically rotating them according to different constraints. This is basically a Log::Dispatch::File wrapper with additions. To that end the arguments .PP .Vb 1 \& name, min_level, filename and mode .Ve .PP behave the same as Log::Dispatch::File. So see its man page (perldoc Log::Dispatch::File) .PP The arguments size and max specify the maximum size and maximum number of log files created. The size defaults to 10M and the max number of files defaults to 1. If DatePattern is not defined then we default to working in size mode. That is, use size values for deciding when to rotate. .PP Once DatePattern is defined FileRotate will move into time mode. Once this happens file rotation ignores size constraints and uses the defined date pattern constraints. .PP If you setup a config file using \fBLog::Log4perl::init_and_watch()\fR or the like, you can switch between modes just by commenting out the DatePattern line. .PP When using DatePattern make sure \s-1TZ\s0 is defined correctly and that the \s-1TZ\s0 you use is understood by Date::Manip. We use Date::Manip to generate our recurrences. Bad \s-1TZ\s0 equals bad recurrences equals surprises! Read the Date::Manip man page for more details on \s-1TZ.\s0 .PP DatePattern will default to a daily rotate if your entered pattern is incorrect. You will also get a warning message. .PP If you have multiple writers that were started at different times you will find each writer will try to rotate the log file at a recurrence calculated from its start time. To sync all the writers just use a config file and update it after starting your last writer. This will cause Log::Dispatch::FileRotate\->\fBnew()\fR to be called by each of the writers close to the same time, and if your recurrences aren't too close together all should sync up just nicely. .PP I initially aasumed a long runinng process but it seems people are using this module as part of short running \s-1CGI\s0 programs. So, now we look at the last modified time stamp of the log file and compare it to a previous occurance of a DatePattern, on startup only. If the file stat shows the mtime to be earlier than the previous recurrance then I rotate the log file. .PP We handle multiple writers using \fBflock()\fR. .SH "DatePattern" .IX Header "DatePattern" As I said earlier we use Date::Manip for generating our recurrence events. This means we can understand Date::Manip's recurrence patterns and the normal log4j DatePatterns. We don't use DatePattern to define the extension of the log file though. .PP DatePattern can therefore take forms like: .PP .Vb 4 \& Date::Manip style \& 0:0:0:0:5:30:0 every 5 hours and 30 minutes \& 0:0:0:2*12:30:0 every 2 days at 12:30 (each day) \& 3*1:0:2:12:0:0 every 3 years on Jan 2 at noon \& \& DailyRollingFileAppender log4j style \& yyyy\-MM every month \& yyyy\-ww every week \& yyyy\-MM\-dd every day \& yyyy\-MM\-dd\-a every day at noon \& yyyy\-MM\-dd\-HH every hour \& yyyy\-MM\-dd\-HH\-MM every minute .Ve .PP To specify multiple recurrences in a single string separate them with a semicolon: yyyy-MM-dd; 0:0:0:2*12:30:0 .PP This says we want to rotate every day \s-1AND\s0 every 2 days at 12:30. Put in as many as you like. .PP A complete description of Date::Manip recurrences is beyond us here except to quote (from the man page): .PP .Vb 4 \& A recur description is a string of the format \& Y:M:W:D:H:MN:S . Exactly one of the colons may \& optionally be replaced by an asterisk, or an asterisk \& may be prepended to the string. \& \& Any value "N" to the left of the asterisk refers to \& the "Nth" one. Any value to the right of the asterisk \& refers to a value as it appears on a calendar/clock. \& Values to the right can be listed a single values, \& ranges (2 numbers separated by a dash "\-"), or a comma \& separated list of values or ranges. In a few cases, \& negative values are appropriate. \& \& This is best illustrated by example. \& \& 0:0:2:1:0:0:0 every 2 weeks and 1 day \& 0:0:0:0:5:30:0 every 5 hours and 30 minutes \& 0:0:0:2*12:30:0 every 2 days at 12:30 (each day) \& 3*1:0:2:12:0:0 every 3 years on Jan 2 at noon \& 0:1*0:2:12,14:0:0 2nd of every month at 12:00 and 14:00 \& 1:0:0*45:0:0:0 45th day of every year \& 0:1*4:2:0:0:0 4th tuesday (day 2) of every month \& 0:1*\-1:2:0:0:0 last tuesday of every month \& 0:1:0*\-2:0:0:0 2nd to last day of every month .Ve .SH "METHODS" .IX Header "METHODS" .IP "\(bu" 4 new(%p) .Sp This method takes a hash of parameters. The following options are valid: .RS 4 .IP "\-\- name ($)" 8 .IX Item "-- name ($)" The name of the object (not the filename!). Required. .IP "\-\- size ($)" 8 .IX Item "-- size ($)" The maxium (or close to) size the log file can grow too. .IP "\-\- max ($)" 8 .IX Item "-- max ($)" The maxium number of log files to create. .IP "\-\- \s-1TZ\s0 ($)" 8 .IX Item "-- TZ ($)" The TimeZone time based calculations should be done in. This should match Date::Manip's concept of timezones and of course your machines timezone. .IP "\-\- DatePattern ($)" 8 .IX Item "-- DatePattern ($)" The DatePattern as defined above. .IP "\-\- min_level ($)" 8 .IX Item "-- min_level ($)" The minimum logging level this object will accept. See the Log::Dispatch documentation for more information. Required. .IP "\-\- max_level ($)" 8 .IX Item "-- max_level ($)" The maximum logging level this obejct will accept. See the Log::Dispatch documentation for more information. This is not required. By default the maximum is the highest possible level (which means functionally that the object has no maximum). .IP "\-\- filename ($)" 8 .IX Item "-- filename ($)" The filename to be opened for writing. This is the base name. Rotated log files will be renamed filename.1 thru to filename.\f(CW\*(C`max\*(C'\fR. Where max is the paramater defined above. .IP "\-\- mode ($)" 8 .IX Item "-- mode ($)" The mode the file should be opened with. Valid options are 'write', \&'>', 'append', '>>', or the relevant constants from Fcntl. The default is 'write'. .IP "\-\- autoflush ($)" 8 .IX Item "-- autoflush ($)" Whether or not the file should be autoflushed. This defaults to true. .IP "\-\- callbacks( \e& or [ \e&, \e&, ... ] )" 8 .IX Item "-- callbacks( & or [ &, &, ... ] )" This parameter may be a single subroutine reference or an array reference of subroutine references. These callbacks will be called in the order they are given and passed a hash containing the following keys: .Sp .Vb 1 \& ( message => $log_message, level => $log_level ) .Ve .Sp The callbacks are expected to modify the message and then return a single scalar containing that modified message. These callbacks will be called when either the \f(CW\*(C`log\*(C'\fR or \f(CW\*(C`log_to\*(C'\fR methods are called and will only be applied to a given message once. .IP "\-\- \s-1DEBUG\s0 ($)" 8 .IX Item "-- DEBUG ($)" Turn on lots of warning messages to \s-1STDERR\s0 about what this module is doing if set to 1. Really only useful to me. .RE .RS 4 .RE .IP "\(bu" 4 log_message( message => $ ) .Sp Sends a message to the appropriate output. Generally this shouldn't be called directly but should be called through the \f(CW\*(C`log()\*(C'\fR method (in Log::Dispatch::Output). .IP "\(bu" 4 setDatePattern( $ or [ $, $, ... ] ) .Sp Set a new suite of recurrances for file rotation. You can pass in a single string or a reference to an array of strings. Multiple recurrences can also be define within a single string by seperating them with a semi-colon (;) .Sp See the discussion above regarding the setDatePattern paramater for more details. .SH "TODO" .IX Header "TODO" compression, signal based rotates, proper test suite .PP Could possibly use Logfile::Rotate as well/instead. .SH "AUTHOR" .IX Header "AUTHOR" Mark Pfeiffer, inspired by Dave Rolsky's, , code :\-) .PP Kevin Goess suggested multiple writers should be supported. He also conned me into doing the time based stuff. Thanks Kevin! :\-) .PP Thanks also to Dan Waldheim for helping with some of the locking issues in a forked environment. .PP And thanks to Stephen Gordon for his more portable code on lockfile naming. .SH "Copyright" .IX Header "Copyright" Copyright 2005\-2006, Mark Pfeiffer .PP This code may be copied only under the terms of the Artistic License, or \&\s-1GPL\s0 License which may be found in the Perl 5 source kit. .PP Use 'perldoc perlartistic' to see the Artistic License. Use 'perldoc perlgpl' to see the \s-1GNU\s0 General Public License. .PP Complete documentation for Perl, including \s-1FAQ\s0 lists, should be found on this system using `man perl' or `perldoc perl'. If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page.