Logfile-Rotate-1.04/000075000001460000146000000000000715263226000145775ustar00paulgstaff00167770000001Logfile-Rotate-1.04/t/000075000001460000146000000000000715263226000150425ustar00paulgstaff00167770000001Logfile-Rotate-1.04/t/05flock.t000064400001460000146000000020130715014016000164620ustar00paulgstaff00167770000001 BEGIN {print "1..15\n";} END {print "not ok 1\n" unless $loaded;} use Logfile::Rotate; $loaded = 1; print "ok 1\n"; use File::Copy; ############################################################################### # T E S T S T R A I G H T R O T A T I O N ############################################################################### my $i = 2; my @bool = qw (yes no); $|=1; while ($bool = pop @bool) { print "\ntesting flock: $bool\n"; my $cnt = 3; my $file_no = 1; copy('t/rotate.log', 't/rotate.tmp'); print "not " unless $log = new Logfile::Rotate( File => 't/rotate.tmp', Count => $cnt , Flock => $bool , Gzip => 'no' ); print "ok ",$i++,"\n"; while($cnt-- > 0) { $log->rotate() or print "not "; print "ok ",$i++,"\n"; my $f = "t/rotate.tmp." . $file_no++; print "not " unless ( -f $f ); print "ok ",$i++,"\n"; copy('t/rotate.log', 't/rotate.tmp'); } while($file_no-- > 0) { my $f = "t/rotate.tmp." . $file_no; unlink $f; } unlink('t/rotate.tmp'); } 1; e.tmp'); print "not " unless $log = new Logfile::Rotate( File => 't/rotate.tmp', Count => $cnt , Flock => $bool , Gzip => 'no' ); print "ok ",$i++,"\n"; while($cnt-- > 0) { $log->rotate() or print "not "; print "ok ",$i++,"\n"; my $f = "t/rotate.tmp." . $file_no++; print "not " unless ( -f $f ); print "ok ",$i++,"\n"; copy('t/rotate.log', 't/rotate.tmp'); } while($file_no-- > 0) { my $f = "t/rotate.tmp." . $file_no; unlink $f; } unlink('t/rotate.tmpLogfile-Rotate-1.04/t/04dir.t000064400001460000146000000017640667212252200161670ustar00paulgstaff00167770000001 BEGIN {print "1..8\n";} END {print "not ok 1\n" unless $loaded;} use Logfile::Rotate; $loaded = 1; print "ok 1\n"; use File::Copy; ############################################################################### # T E S T D I R A T T R I B U T E ############################################################################### my $i = 2; my $cnt = 3; my $file_no = 1; copy('t/rotate.log', 't/rotate.tmp'); print "not " unless $log = new Logfile::Rotate( File => 't/rotate.tmp', Count => $cnt , Gzip => 'no' , Dir => 't/tmp' ); print "ok ",$i++,"\n"; while($cnt-- > 0) { $log->rotate() or print "not "; print "ok ",$i++,"\n"; my $f = "t/tmp/rotate.tmp." . $file_no++; print "not " unless ( -f $f ); print "ok ",$i++,"\n"; copy('t/rotate.log', 't/rotate.tmp'); } while($file_no-- > 0) { my $f = "t/tmp/rotate.tmp." . $file_no; unlink $f; } unlink('t/rotate.tmp'); rmdir ('t/tmp'); 1; tmp', Logfile-Rotate-1.04/t/03compress.t000064400001460000146000000021600667212252200172320ustar00paulgstaff00167770000001 BEGIN {print "1..8\n";} END {print "not ok 1\n" unless $loaded;} use Config; use Logfile::Rotate; $loaded = 1; print "ok 1\n"; use File::Copy; ############################################################################### # T E S T C O M P R E S S A T T R I B U T E ############################################################################### # skip if perl does not know about gzip # my $Config; $Config{'gzip'} = undef; unless (defined ($Config{'gzip'})) { for ($i=2; $i<9; $i++) { print "ok $i # skipped on your platform\n"; } exit 0; } $i=2; $cnt = 3; $file_no = 1; copy('t/rotate.log', 't/rotate.tmp'); print "not " unless $log = new Logfile::Rotate( File => 't/rotate.tmp', Count => $cnt ); print "ok ",$i++,"\n"; while($cnt-- > 0) { $log->rotate() or print "not "; print "ok ",$i++,"\n"; my $f = "t/rotate.tmp." . $file_no++ . ".gz"; print "not " unless( -f $f ); print "ok ",$i++,"\n"; copy('t/rotate.log', 't/rotate.tmp'); } while($file_no-- > 0) { my $f = "t/rotate.tmp." . $file_no . ".gz"; unlink $f; } unlink('t/rotate.tmp'); 1; og', 't/rotate.tmp'); print "not " unless $log = new Logfile::Rotate( File => 't/rotate.tmp', Count => $cnt ); print "ok ",$i++,"\n"; while($cnt-- > 0) { $log->rotate() or print "not "; print "ok ",$i++,"\n"; my $f = "t/rotate.tmp." . $file_no++ . ".gz"; print "not " unless( -f $f ); print "ok ",$i++,"\n"; copy('t/rotate.log', 't/rotate.tmp'); } Logfile-Rotate-1.04/t/rotate.log000064400001460000146000000041020667206230300170460ustar00paulgstaff00167770000001|000 nul|001 soh|002 stx|003 etx|004 eot|005 enq|006 ack|007 bel| |010 bs |011 ht |012 nl |013 vt |014 np |015 cr |016 so |017 si | |020 dle|021 dc1|022 dc2|023 dc3|024 dc4|025 nak|026 syn|027 etb| |030 can|031 em |032 sub|033 esc|034 fs |035 gs |036 rs |037 us | |040 sp |041 ! |042 " |043 # |044 $ |045 % |046 & |047 ' | |050 ( |051 ) |052 * |053 + |054 , |055 - |056 . |057 / | |060 0 |061 1 |062 2 |063 3 |064 4 |065 5 |066 6 |067 7 | |070 8 |071 9 |072 : |073 ; |074 < |075 = |076 > |077 ? | |100 @ |101 A |102 B |103 C |104 D |105 E |106 F |107 G | |110 H |111 I |112 J |113 K |114 L |115 M |116 N |117 O | |120 P |121 Q |122 R |123 S |124 T |125 U |126 V |127 W | |130 X |131 Y |132 Z |133 [ |134 \ |135 ] |136 ^ |137 _ | |140 ` |141 a |142 b |143 c |144 d |145 e |146 f |147 g | |150 h |151 i |152 j |153 k |154 l |155 m |156 n |157 o | |160 p |161 q |162 r |163 s |164 t |165 u |166 v |167 w | |170 x |171 y |172 z |173 { |174 | |175 } |176 ~ |177 del| | 00 nul| 01 soh| 02 stx| 03 etx| 04 eot| 05 enq| 06 ack| 07 bel| | 08 bs | 09 ht | 0a nl | 0b vt | 0c np | 0d cr | 0e so | 0f si | | 10 dle| 11 dc1| 12 dc2| 13 dc3| 14 dc4| 15 nak| 16 syn| 17 etb| | 18 can| 19 em | 1a sub| 1b esc| 1c fs | 1d gs | 1e rs | 1f us | | 20 sp | 21 ! | 22 " | 23 # | 24 $ | 25 % | 26 & | 27 ' | | 28 ( | 29 ) | 2a * | 2b + | 2c , | 2d - | 2e . | 2f / | | 30 0 | 31 1 | 32 2 | 33 3 | 34 4 | 35 5 | 36 6 | 37 7 | | 38 8 | 39 9 | 3a : | 3b ; | 3c < | 3d = | 3e > | 3f ? | | 40 @ | 41 A | 42 B | 43 C | 44 D | 45 E | 46 F | 47 G | | 48 H | 49 I | 4a J | 4b K | 4c L | 4d M | 4e N | 4f O | | 50 P | 51 Q | 52 R | 53 S | 54 T | 55 U | 56 V | 57 W | | 58 X | 59 Y | 5a Z | 5b [ | 5c \ | 5d ] | 5e ^ | 5f _ | | 60 ` | 61 a | 62 b | 63 c | 64 d | 65 e | 66 f | 67 g | | 68 h | 69 i | 6a j | 6b k | 6c l | 6d m | 6e n | 6f o | | 70 p | 71 q | 72 r | 73 s | 74 t | 75 u | 76 v | 77 w | | 78 x | 79 y | 7a z | 7b { | 7c | | 7d } | 7e ~ | 7f del| | 42 B | 43 C | 44 D | 45 E | 46 F | 47 G | | 48 H | 49 I | 4a J | 4b K | 4c L | 4d M | 4e N | 4f O | | 50 P | 51 Q | 52 R | 53 S | 54 T | 55 U | 56 V | 57 W | | 58 X | 59 Y | 5a Z | 5b [ | 5c \ | 5d ] | 5e ^ | 5f _ | | 60 ` | 61 a | 62 b | 63 c | 64 d | 65 e | 66 f | 67 g | | 68 h | 69 i | 6a j | 6b k | 6c l | 6d m | 6e n | 6f o | | 70 p | 71 q | 72 r | 73 s | 74 t | 75 u | 76 v | 77 w | Logfile-Rotate-1.04/t/01rotate.t000064400001460000146000000016770667212252200167070ustar00paulgstaff00167770000001 BEGIN {print "1..8\n";} END {print "not ok 1\n" unless $loaded;} use Logfile::Rotate; $loaded = 1; print "ok 1\n"; use File::Copy; ############################################################################### # T E S T S T R A I G H T R O T A T I O N ############################################################################### my $i = 2; my $cnt = 3; my $file_no = 1; copy('t/rotate.log', 't/rotate.tmp'); print "not " unless $log = new Logfile::Rotate( File => 't/rotate.tmp', Count => $cnt , Gzip => 'no' ); print "ok ",$i++,"\n"; while($cnt-- > 0) { $log->rotate() or print "not "; print "ok ",$i++,"\n"; my $f = "t/rotate.tmp." . $file_no++; print "not " unless ( -f $f ); print "ok ",$i++,"\n"; copy('t/rotate.log', 't/rotate.tmp'); } while($file_no-- > 0) { my $f = "t/rotate.tmp." . $file_no; unlink $f; } unlink('t/rotate.tmp'); 1; unless $log = new Logfile::Rotate( File => 't/rotate.tmp', Logfile-Rotate-1.04/t/07pre.t000064400001460000146000000020460715014016000161620ustar00paulgstaff00167770000001 BEGIN {print "1..15\n";} END {print "not ok 1\n" unless $loaded;} use Logfile::Rotate; $loaded = 1; print "ok 1\n"; use File::Copy; ############################################################################### # T E S T S T R A I G H T R O T A T I O N ############################################################################### my $i = 2; $t1 = sub { print "test 1\n"; }; $t2 = sub { print "test 2\n"; }; my @subs = ($t1, $t2); $|=1; while ($sub = pop @subs) { my $cnt = 3; my $file_no = 1; copy('t/rotate.log', 't/rotate.tmp'); print "not " unless $log = new Logfile::Rotate( File => 't/rotate.tmp', Count => $cnt , Pre => $sub, Gzip => 'no' ); print "ok ",$i++,"\n"; while($cnt-- > 0) { $log->rotate() or print "not "; print "ok ",$i++,"\n"; my $f = "t/rotate.tmp." . $file_no++; print "not " unless ( -f $f ); print "ok ",$i++,"\n"; copy('t/rotate.log', 't/rotate.tmp'); } while($file_no-- > 0) { my $f = "t/rotate.tmp." . $file_no; unlink $f; } unlink('t/rotate.tmp'); } 1; tate.tmp'); print "not " unless $log = new Logfile::Rotate( File => 't/rotate.tmp', Count => $cnt , Pre => $sub, Gzip => 'no' ); print "ok ",$i++,"\n"; while($cnt-- > 0) { $log->rotate() or print "not "; print "ok ",$i++,"\n"; my $f = "t/rotate.tmp." . $file_no++; print "not " unless ( -f $f ); print "ok ",$i++,"\n"; copy('t/rotate.log', 't/rotate.tmp'); } while($file_no-- > 0) { my $f = "t/rotate.tmp." . $file_no; unlink $fLogfile-Rotate-1.04/t/09lib_compress.t000064400001460000146000000022050715014016000200540ustar00paulgstaff00167770000001 BEGIN {print "1..8\n";} END {print "not ok 1\n" unless $loaded;} use Config; use Logfile::Rotate; $loaded = 1; print "ok 1\n"; use File::Copy; ############################################################################### # T E S T C O M P R E S S A T T R I B U T E ############################################################################### # skip if Compress::Zlib is not installed eval { require Compress::Zlib; }; if ($@) { for ($i=2; $i<9; $i++) { print "ok $i # skipped on your platform\n"; } exit 0; } $i=2; $cnt = 3; $file_no = 1; copy('t/rotate.log', 't/rotate.tmp'); print "not " unless $log = new Logfile::Rotate( File => 't/rotate.tmp', Gzip => 'lib', Count => $cnt ); print "ok ",$i++,"\n"; while($cnt-- > 0) { $log->rotate() or print "not "; print "ok ",$i++,"\n"; my $f = "t/rotate.tmp." . $file_no++ . ".gz"; print "not " unless( -f $f ); print "ok ",$i++,"\n"; copy('t/rotate.log', 't/rotate.tmp'); } while($file_no-- > 0) { my $f = "t/rotate.tmp." . $file_no . ".gz"; unlink $f; } unlink('t/rotate.tmp'); 1; new Logfile::Rotate( File => 't/rotate.tmp', Gzip => 'lib', Count => $cnt ); print "ok ",$i++,"\n"; while($cnt-- > 0) { $log->rotate() or print "not "; print "ok ",$i++,"\n"; my $f = "t/rotate.tmp." . $file_no++ . ".gz"; print "not " unless( -f $f ); print "ok ",$i++,"\n"; copy('t/rotate.log',Logfile-Rotate-1.04/t/08post.t000064400001460000146000000020550715014016000163620ustar00paulgstaff00167770000001 BEGIN {print "1..15\n";} END {print "not ok 1\n" unless $loaded;} use Logfile::Rotate; $loaded = 1; print "ok 1\n"; use File::Copy; ############################################################################### # T E S T S T R A I G H T R O T A T I O N ############################################################################### my $i = 2; $t1 = sub { print "test 1 @_\n"; }; $t2 = sub { print "test 2 @_\n"; }; my @subs = ($t1, $t2); $|=1; while ($sub = pop @subs) { my $cnt = 3; my $file_no = 1; copy('t/rotate.log', 't/rotate.tmp'); print "not " unless $log = new Logfile::Rotate( File => 't/rotate.tmp', Count => $cnt , Post => $sub, Gzip => 'no' ); print "ok ",$i++,"\n"; while($cnt-- > 0) { $log->rotate() or print "not "; print "ok ",$i++,"\n"; my $f = "t/rotate.tmp." . $file_no++; print "not " unless ( -f $f ); print "ok ",$i++,"\n"; copy('t/rotate.log', 't/rotate.tmp'); } while($file_no-- > 0) { my $f = "t/rotate.tmp." . $file_no; unlink $f; } unlink('t/rotate.tmp'); } 1; ate.tmp'); print "not " unless $log = new Logfile::Rotate( File => 't/rotate.tmp', Count => $cnt , Post => $sub, Gzip => 'no' ); print "ok ",$i++,"\n"; while($cnt-- > 0) { $log->rotate() or print "not "; print "ok ",$i++,"\n"; my $f = "t/rotate.tmp." . $file_no++; print "not " unless ( -f $f ); print "ok ",$i++,"\n"; copy('t/rotate.log', 't/rotate.tmp'); } while($file_no-- > 0) { my $f = "t/rotate.tmp." . $file_no; unLogfile-Rotate-1.04/t/06persist.t000064400001460000146000000027710715014016000170710ustar00paulgstaff00167770000001 BEGIN {print "1..30\n";} END {print "not ok 1\n" unless $loaded;} use Logfile::Rotate; $loaded = 1; print "ok 1\n"; use File::Copy; ############################################################################### # T E S T S T R A I G H T R O T A T I O N ############################################################################### my $i = 2; my @bool = qw (yes no); $|=1; while ($bool = pop @bool) { print "\ntesting persist: $bool\n"; my $cnt = 3; my $file_no = 1; copy('t/rotate.log', 't/rotate.tmp'); print "not " unless $log = new Logfile::Rotate( File => 't/rotate.tmp', Count => $cnt , Persist => $bool , Gzip => 'no' ); print "ok ",$i++,"\n"; while($cnt-- > 0) { $log->rotate() or print "not "; print "ok ",$i++,"\n"; my $f = "t/rotate.tmp." . $file_no++; print "not " unless ( -f $f ); print "ok ",$i++,"\n"; if ($bool eq 'yes') { my @old_stat = stat 't/rotate.tmp'; my @new_stat = stat $f; print "not " unless $old_stat[2] == $new_stat[2]; print "ok ",$i++,"\n"; print "not " unless $old_stat[8] == $new_stat[8]; print "ok ",$i++,"\n"; print "not " unless $old_stat[9] == $new_stat[9]; print "ok ",$i++,"\n"; print "not " unless $old_stat[4] == $new_stat[4]; print "ok ",$i++,"\n"; print "not " unless $old_stat[5] == $new_stat[5]; print "ok ",$i++,"\n"; } copy('t/rotate.log', 't/rotate.tmp'); } while($file_no-- > 0) { my $f = "t/rotate.tmp." . $file_no; unlink $f; } unlink('t/rotate.tmp'); } 1; _stat[2Logfile-Rotate-1.04/t/02signal.t000064400001460000146000000017770667212252200166700ustar00paulgstaff00167770000001 BEGIN {print "1..8\n";} END {print "not ok 1\n" unless $loaded;} use Logfile::Rotate; $loaded = 1; print "ok 1\n"; use File::Copy; ############################################################################### # T E S T S I G N A L A T T R I B U T E ############################################################################### my $i = 2; copy('t/rotate.log', 't/rotate.tmp'); $cnt = 3; $file_no = 1; print "not " unless $log = new Logfile::Rotate( File => 't/rotate.tmp', Count => $cnt, Gzip => 'no', Signal => sub { print "ok "; }, ); print "ok ",$i++,"\n"; while($cnt-- > 0) { $log->rotate() or print "not "; print $i++,"\n"; ## rotate print's ok my $f = "t/rotate.tmp." . $file_no++; print "not " unless ( -f $f ); print "ok ",$i++,"\n"; copy('t/rotate.log', 't/rotate.tmp'); } while($file_no-- > 0) { my $f = "t/rotate.tmp." . $file_no; unlink $f; } unlink('t/rotate.tmp'); 1; Logfile-Rotate-1.04/README000064400001460000146000000164040715263226000154710ustar00paulgstaff00167770000001NAME Logfile::Rotate - Perl module to rotate logfiles. SYNOPSIS use Logfile::Rotate; my $log = new Logfile::Rotate( File => '/var/adm/syslog/syslog.log', Count => 7, Gzip => 'lib', Post => sub{ open(IN, "/var/run/syslog.pid"); kill("HUP", chomp()); } Dir => '/var/log/old', Flock => 'yes', Persist => 'yes', ); # process log file $log->rotate(); or my $log = new Logfile::Rotate( File => '/var/adm/syslog', Gzip => '/usr/local/bin/gzip'); # process log file $log->rotate(); undef $log; DESCRIPTION I have used the name space of the Logfile::Base manpage package by *Ulrich Pfeifer*, as the use of this module closely relates to the processing logfiles. new `new' accepts the following arguments, `File', `Count', `Gzip', `Pre', `Post', `Flock' and `Dir' with only `File' being mandatory. `new' will open and lock the file, so you may co-ordinate the processing of the file with rotating it. The file is closed and unlocked when the object is destroyed, so you can do this explicitly by `undef''ing the object. The `Pre'/`Post' arguments allow you to pass function references to this method, which you may use as a callback for any processing you want before or after the rotation. For example, you may notify the process writing to the file that it has been rotated. The `Pre' function is passed the current filename to be rotated as an argument and the `Post' function is passed the current filename that was rotated and that file's new filename including any extension added by compression previously. Both the `Pre' and `Post' function references you provide are executed within an `eval' statement inside the `rotate' method. If the `eval' returns an error then the `rotate' method will croak at that point. The `Signal' argument is deprecated by the `Post' argument. The `Flock' argument allows you to specify whether the perl function `flock' is used to lock the file during the rotation operation. Apparently flock causes problems on some platforms and this option has been added to allow you to control the programs behaviour. By default the file will be locked using `flock'. The `Persist' argument allows you to control whether the program will try and set the current log file ownership and permissions on any new files that may be created by the rotation. In some circumstances the program doing the file rotation may not have sufficient permission to `chown' on the file. By default the program will try and preserve ownership and permissions. rotate() This method will copy the file passed in `new' to a file of the same name, with a numeric extension and truncate the original file to zero length. The numeric extension will range from 1 up to the value specified by Count, or 7 if none is defined, with 1 being the most recent file. When Count is reached, the older file is discarded in a FIFO (first in, first out) fashion. If the argument `Dir' was given, all old files will be placed in the specified directory. The `Post' function is the last step executed by the rotate method so the return code of rotate will be the return code of the function you proved, or 1 by default. The copy function is implemented by using the the File::Copy manpage package, but I have had a few people suggest that they would prefer the File::Move manpage. I'm still not decided on this as you would loose data if the move should fail. Optional Compression If available `rotate' will also compress the file with the the gzip manpage program or the program passed as the `Gzip' argument. You may now also use `lib' as a value for the `Gzip' argument. This directs the program to load the `Compress::Zlib' module, if available and use it do the compression within perl. This avoids the security issues associated with spawning external programs and is the recommended value for this option. If no argument is defined it will first check to see if the `Compress::Zlib' module can be loaded then check the perl the Config manpage to determine if gzip is available on your system. In this case the the gzip manpage must be in your current path to succeed, and accept the `-f' option. See the the section on "WARNING" section below. Optional Relocation Directory If you specify an argument for `Dir' then the file being rotated will be relocated to the directory specified. Along with any other files that may have been rotated previously. If the directory name specified does not exist then it will be created with `0750' permissions. If you wish to have other permissions on the directory then I would recommend you create the directory before using this module. See the the section on "WARNING" section below. WARNING If a system call is made to gzip this makes this module vulnerable to security problems if a rogue gzip is in your path or gzip has been sabotaged. For this reason a STRONGLY RECOMMEND you DO NOT use this module while you are ROOT. For a more secure alternative install the `Compress::Zlib' module and use the lib value for the `Gzip' argument. If you specify an argument for `Dir' and the directory name you pass does not exist, this module will create the directory with permissions `0750'. DEPENDANCIES See the File::Copy manpage. If `Gzip' is being used it must create files with an extension of `.gz' for the file to be picked by the rotate cycle. COPYRIGHT Copyright (c) 1997-99 Paul Gampe. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN ``AS IS'' BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. SEE ALSO the File::Copy manpage, the Logfile::Base manpage, the flock manpage Changes file for change history and credits for contributions. RETURN All functions return 1 on success, 0 on failure. AUTHOR Paul Gampe ERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN ``AS IS'' BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICALogfile-Rotate-1.04/MANIFEST000064400001460000146000000003150715263165100157370ustar00paulgstaff00167770000001Changes Logfile-Rotate.man.html MANIFEST Makefile.PL README Rotate.pm TODO t/01rotate.t t/02signal.t t/03compress.t t/04dir.t t/05flock.t t/06persist.t t/07pre.t t/08post.t t/09lib_compress.t t/rotate.log _1lureUTHOì01“Y0 ÜÐ0Ll X_1, t> ERCHANTAœo1FITN^d0 ÜÐ0Ll X_1, POSE, AND NON-IN, Ïkpc1, ÜÐ0Ll X_1VIDED ON AN ``ASýŸ  , `¤XHORSüwîŠèAff²4«9Ô[t°4«9Ñš—°4«9Ñš— ௼lÜÐ0Ll pc1Logfile-Rotate-1.04/Changes000064400001460000146000000047710715263224300161110ustar00paulgstaff00167770000001# Revision history for Perl extension Logfile. # # $Log: Changes,v $ # Revision 1.4 2000/08/29 03:57:23 paulg # Added a range of features requested by Jerrad Pierce # , who also contributed code! Thanks # Jerrard. These features include an option to use flock or not, preserve # file permissions is now optional, and if you have Compress::Zlib then it # can be used instead of spawning an external call to gzip. # # Revision 1.3 1999/03/12 05:28:40 paulg # Incrementing revision no. # # Revision 1.2 1999/03/12 05:25:32 paulg # Added an option to stored rotated files in a separate directory. This # feature has been requested before but fortunately Bas Zoetekouw # , contributed some code. # # Revision 1.1.1.1 1999/03/12 00:50:11 paulg # importing from cpan to cvs repository as I've changed jobs, and don't # have access to my old build tree. The version numbers are going to # be reset, but this should be ok as the current version on CPAN 1.02. # So look at the dates not the serial no. in this file. # # Revision 1.7 98/03/24 12:52:46 12:52:46 paulg (Paul Gampe) # Added reference to Changes file for credits to contributions. # # Revision 1.6 98/03/24 12:45:29 12:45:29 paulg (Paul Gampe) # Switched from File::Copy::copy to File::Copy::move for rotating the old # logfiles, to preserve permissions and reduce disk space consumption. # File::Copy::move will try to do a rename. # Suggested by: webmaster # and "Mike Arms (6531)" . # Added code to copy the current log file permissions to first incremental. # Code and concept by: "Mike Arms (6531)" . # # Revision 1.5 98/03/24 12:31:11 12:31:11 paulg (Paul Gampe) # Added an argument Signal so that you can get a callback function executed # as soon as the rotation is complete. Code and ideas contributed by: # "M. S. Sriram" , # and Mike Frohme # # Revision 1.4 98/03/24 10:31:03 10:31:03 paulg (Paul Gampe) # bug fix with flock reported by: # # Revision 1.3 98/03/03 14:36:29 14:36:29 paulg (Paul Gampe) # Adding copyright section to man page # # Revision 1.2 98/02/18 16:03:35 16:03:35 paulg (Paul Gampe) # Format fixup to manpage # # Revision 1.1 97/12/08 14:32:31 14:32:31 paulg (Paul Gampe) # Initial revision # # 0.01 Mon Dec 1 14:02:52 1997 # - original version; created by h2xs 1.18 # # his.eduLogfile-Rotate-1.04/Makefile.PL000064400001460000146000000010570667212677000165730ustar00paulgstaff00167770000001use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Logfile::Rotate', 'VERSION_FROM' => 'Rotate.pm', # finds $VERSION 'PREREQ_PM' => { 'File::Copy' => 2.02 }, # requires 'dist' => { PREOP => '/opt/perl5/bin/pod2text Rotate.pm > README;\ /opt/perl5/bin/pod2html --noindex \ Rotate.pm > Logfile-Rotate.man.html', COMPRESS=> 'gzip -9f', SUFFIX=>'gz', }, ); eMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Logfile::Rotate', 'VERSION_FROM' => 'Rotate.pm', # finds $VERSION 'PREREQ_PM' => { 'File::Copy' => 2.02 }, # requires 'dist' => { PREOP => '/opt/perl5/bin/pod2text Rotate.pm > README;\ /opt/perl5/bin/pod2html --noindex \ Rotate.pm > Logfile-Rotate.man.html', Logfile-Rotate-1.04/Rotate.pm000064400001460000146000000335020715263224300164040ustar00paulgstaff00167770000001#!/usr/bin/perl ############################################################################### # # $Id: Rotate.pm,v 1.5 2000/08/29 03:57:23 paulg Exp $ vim:ts=4 # # Copyright (c) 1997-99 Paul Gampe. All Rights Reserved. # # This program is free software; you can redistribute it and/or modify it # under the same terms as Perl itself. See COPYRIGHT section below. # ############################################################################### ############################################################################### ## L I B R A R I E S / M O D U L E S ############################################################################### package Logfile::Rotate; use Config; # do we have gzip use Carp; use IO::File; use File::Copy; use Fcntl qw(:flock); use strict; ############################################################################### ## G L O B A L V A R I A B L E S ############################################################################### use vars qw($VERSION $COUNT $GZIP_FLAG); $VERSION = do { my @r=(q$Revision: 1.5 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r}; $COUNT =7; # default to keep 7 copies $GZIP_FLAG='-qf'; # force writing over old logfiles ############################################################################### ## E X P O R T S ############################################################################### ############################################################################### ## M A I N ############################################################################### sub new { my ($class, %args) = @_; croak("usage: new( File => filename [, Count => cnt ] [, Gzip => lib or \"/path/to/gzip\" or no ] [, Signal => \&sub_signal ] [, Pre => \&sub_pre ] [, Post => \&sub_post ] [, Flock => yes or no ] [, Persist => yes or no ] [, Dir => \"dir/to/put/old/files/into\"] )") unless defined($args{'File'}); my $self = {}; $self->{'Fh'} = undef; $self->{'File'} = $args{'File'}; $self->{'Count'} = ($args{'Count'} or 7); $self->{'Signal'} = ($args{'Signal'} or sub {1;}); $self->{'Pre'} = ($args{'Pre'} or sub {1;}); $self->{'Post'} = ($args{'Post'} or sub {1;}); $self->{'Flock'} = ($args{'Flock'} or 'yes'); $self->{'Persist'} = ($args{'Persist'} or 'yes'); # deprecated methods carp "Signal is a deprecated argument, see Pre/Post" if $args{'Signal'}; # mutual excl croak "Can not define both Signal and Post" if ($args{Signal} and $args{Post}); (ref($self->{'Signal'}) eq "CODE") or croak "error: Signal is not a CODE reference."; (ref($self->{'Pre'}) eq "CODE") or croak "error: Pre is not a CODE reference."; (ref($self->{'Post'}) eq "CODE") or croak "error: Post is not a CODE reference."; # Process compression arg unless ($args{Gzip}) { if (_have_compress_zlib()) { $self->{Gzip} = 'lib'; } else { $self->{Gzip} = $Config{gzip}; } } else { if ($args{Gzip} eq 'no') { $self->{Gzip} = undef; } else { $self->{Gzip} = $args{Gzip}; } } # Process directory arg if (defined($args{'Dir'})) { $self->{'Dir'} = $args{'Dir'}; # don't know about creating directories ?? mkdir($self->{'Dir'},0750) unless (-d $self->{'Dir'}); } else { $self->{'Dir'} = undef; } # confirm existence of dir if (defined $self->{'Dir'} ) { croak "error: $self->{'Dir'} not writable" unless (-w $self->{'Dir'}); croak "error: $self->{'Dir'} not executable" unless (-x $self->{'Dir'}); } # open and lock the file if( $self->{'Flock'} eq 'yes'){ $self->{'Fh'} = new IO::File "$self->{'File'}", O_WRONLY|O_EXCL; croak "error: can not lock open: ($self->{'File'})" unless defined($self->{'Fh'}); flock($self->{'Fh'},LOCK_EX); } else{ $self->{'Fh'} = new IO::File "$self->{'File'}"; croak "error: can not open: ($self->{'File'})" unless defined($self->{'Fh'}); } bless $self, $class; } sub rotate { my ($self, %args) = @_; my ($prev,$next,$i,$j); # check we still have a filehandle croak "error: lost file handle, may have called rotate twice ?" unless defined($self->{'Fh'}); my $curr = $self->{'File'}; my $currn = $curr; my $ext = $self->{'Gzip'} ? '.gz' : ''; # Execute and exit if Pre method fails eval { &{$self->{'Pre'}}($curr); } if $self->{Pre}; croak "error: your supplied Pre function failed: $@" if ($@); # TODO: what is this doing ?? my $dir = defined($self->{'Dir'}) ? "$self->{'Dir'}/" : ""; $currn =~ s+.*/([^/]*)+$self->{'Dir'}/$1+ if defined($self->{'Dir'}); for($i = $self->{'Count'}; $i > 1; $i--) { $j = $i - 1; $next = "${currn}." . $i . $ext; $prev = "${currn}." . $j . $ext; if ( -r $prev && -f $prev ) { move($prev,$next) ## move will attempt rename for us or croak "error: move failed: ($prev,$next)"; } } ## copy current to next incremental $next = "${currn}.1"; copy ($curr, $next); ## preserve permissions and status if ( $self->{'Persist'} eq 'yes' ){ my @stat = stat $curr; chmod( $stat[2], $next ) or carp "error: chmod failed: ($next)"; utime( $stat[8], $stat[9], $next ) or carp "error: failed: ($next)"; chown( $stat[4], $stat[5], $next ) or carp "error: chown failed: ($next)"; } # now truncate the file if( $self->{'Flock'} eq 'yes' ) { truncate $curr,0 or croak "error: could not truncate $curr: $!"; } else{ local(*IN); open(IN, "+>$self->{'File'}") or croak "error: could not truncate $curr: $!"; } if ($self->{'Gzip'} and $self->{'Gzip'} eq 'lib') { _gzip($next, $next.$ext); } elsif ($self->{'Gzip'}) { # WARNING: may not be safe system call ( 0 == (system $self->{'Gzip'}, $GZIP_FLAG, $next) ) or croak "error: ", $self->{'Gzip'}, " failed"; } # TODO: deprecated: remove next release eval { &{$self->{'Signal'}}($curr, $next); } if ($self->{Signal}); croak "error: your supplied Signal function failed: $@" if ($@); # Execute and exit on post method eval { &{$self->{'Post'}}($curr, $next); } if $self->{Post}; croak "error: your supplied Post function failed: $@" if ($@); # if we made it here we have succeeded return 1; } sub DESTROY { my ($self, %args) = @_; return unless $self->{'Fh'}; # already gone flock($self->{'Fh'},LOCK_UN); undef $self->{'Fh'}; # auto-close } sub _have_compress_zlib { # try and load the compression library eval { require Compress::Zlib; }; if ($@) { carp "warning: could not load Compress::Zlib, skipping compression" ; return undef; } return 1; } sub _gzip { my $in = shift; my $out = shift; # ASSERT croak "error: _gzip called without mandatory argument" unless $in; return unless _have_compress_zlib(); my($buffer,$fhw); $fhw = new IO::File $in or croak "error: could not open $in: $!"; my $gz = Compress::Zlib::gzopen($out, "wb") or croak "error: could not gzopen $out: $!"; $gz->gzwrite($buffer) while read($fhw,$buffer,4096) > 0 ; $gz->gzclose() ; $fhw->close; unlink $in or croak "error: could not delete $in: $!"; return 1; } 1; __END__ =head1 NAME Logfile::Rotate - Perl module to rotate logfiles. =head1 SYNOPSIS use Logfile::Rotate; my $log = new Logfile::Rotate( File => '/var/adm/syslog/syslog.log', Count => 7, Gzip => 'lib', Post => sub{ open(IN, "/var/run/syslog.pid"); kill("HUP", chomp()); } Dir => '/var/log/old', Flock => 'yes', Persist => 'yes', ); # process log file $log->rotate(); or my $log = new Logfile::Rotate( File => '/var/adm/syslog', Gzip => '/usr/local/bin/gzip'); # process log file $log->rotate(); undef $log; =head1 DESCRIPTION I have used the name space of L package by I, as the use of this module closely relates to the processing logfiles. =over 4 =item new C accepts the following arguments, C, C, C, C
, C, C and C with only C being mandatory.
C will open and lock the file, so you may co-ordinate the
processing of the file with rotating it.  The file is closed and
unlocked when the object is destroyed, so you can do this explicitly by
C'ing the object.  

The C
/C arguments allow you to pass function references to
this method, which you may use as a callback for any processing you want
before or after the rotation. For example, you may notify the process
writing to the file that it has been rotated.

The C
 function is passed the current filename to be rotated as an
argument and the C function is passed the current filename that
was rotated and that file's new filename including any extension added
by compression previously.

Both the C
 and C function references you provide are executed
within an C statement inside the C method.  If the C
returns an error then the C method will croak at that point.

The C argument is deprecated by the C argument.

The C argument allows you to specify whether the perl function
C is used to lock the file during the rotation operation.
Apparently flock causes problems on some platforms and this option has
been added to allow you to control the programs behaviour.  By default
the file will be locked using C.

The C argument allows you to control whether the program will
try and set the current log file ownership and permissions on any new
files that may be created by the rotation.  In some circumstances the
program doing the file rotation may not have sufficient permission to
C on the file.  By default the program will try and preserve
ownership and permissions.

=item rotate()

This method will copy the file passed in C to a file of the same
name, with a numeric extension and truncate the original file to zero
length.  The numeric extension will range from 1 up to the value
specified by Count, or 7 if none is defined, with 1 being the most
recent file.  When Count is reached, the older file is discarded in a
FIFO (first in, first out) fashion. If the argument C was given, 
all old files will be placed in the specified directory.

The C function is the last step executed by the rotate method so
the return code of rotate will be the return code of the function you
proved, or 1 by default.

The copy function is implemented by using the L package, but
I have had a few people suggest that they would prefer L.
I'm still not decided on this as you would loose data if the move should
fail.  

=back 

=head2 Optional Compression

If available C will also compress the file with the 
L program or the program passed as the C argument.  

You may now also use C as a value for the C argument.  This
directs the program to load the C module, if available
and use it do the compression within perl.  B

If no argument is defined it will first check to see if the
C module can be loaded then check the perl L to
determine if gzip is available on your system. In this case the L
must be in your current path to succeed, and accept the C<-f> option.  

See the L<"WARNING"> section below.

=head2 Optional Relocation Directory

If you specify an argument for C then the file being rotated will
be relocated to the directory specified.  Along with any other files
that may have been rotated previously.  If the directory name specified
does not exist then it will be created with C<0750> permissions.  If you
wish to have other permissions on the directory then I would recommend
you create the directory before using this module.

See the L<"WARNING"> section below.

=head1 WARNING

If a system call is made to F this makes this module vulnerable to
security problems if a rogue gzip is in your path or F has been
sabotaged.  For this reason a STRONGLY RECOMMEND you DO NOT use this
module while you are ROOT.

For a more secure alternative install the C module and
use the B value for the C argument.

If you specify an argument for C and the directory name you pass
does not exist, this module B the directory with
permissions C<0750>.

=head1 DEPENDANCIES

See L.

If C is being used it must create files with an extension 
of C<.gz> for the file to be picked by the rotate cycle.

=head1 COPYRIGHT

Copyright (c) 1997-99 Paul Gampe. All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. 

THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN ``AS IS'' BASIS, AND
THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 

=head1 SEE ALSO

L, L, L
F file for change history and credits for contributions.

=head1 RETURN

All functions return 1 on success, 0 on failure.

=head1 AUTHOR

Paul Gampe 

=cut

PLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN ``AS IS'' BASIS, AND
THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATLogfile-Rotate-1.04/TODO000064400001460000146000000002040667212251500152730ustar00paulgstaff00167770000001o Thinking about using the Compress::* modules to avoid the dependancy
  on external programs, but need some more feedback on this?
flock>
F file for change history and credits for co\GÜÐ0Ll¸o1 RET
Allì01“Y0ÜÐ0Ll¸o1,0 on failureü11 AU^d0ÜÐ0Ll¸o1,apnic.net>

=cut,ÏkÐs1,ÜÐ0Ll¸o1Y, FITNESS FOR AýŸ  ,´¤X
NONüwîŠèAff²4«9ü[t°4«9Ñš—°4«9Ñš— ௼lÜÐ0LlÐs1Logfile-Rotate-1.04/Logfile-Rotate.man.html000064400001460000146000000224070715263226100210670ustar00paulgstaff00167770000001

Logfile::Rotate - Perl module to rotate logfiles.










NAME

Logfile::Rotate - Perl module to rotate logfiles.


SYNOPSIS

   use Logfile::Rotate;
   my $log = new Logfile::Rotate( File   => '/var/adm/syslog/syslog.log', 
                                  Count  => 7,
                                  Gzip  => 'lib',
                                  Post   => sub{ 
                                    open(IN, "/var/run/syslog.pid");
                                    kill("HUP", chomp(<IN>)); }
                                  Dir    => '/var/log/old',
                                  Flock  => 'yes',
                                  Persist => 'yes',
                                );
   # process log file
   $log->rotate();
   or

   my $log = new Logfile::Rotate( File  => '/var/adm/syslog', 
                                  Gzip   => '/usr/local/bin/gzip');

   # process log file
   $log->rotate();
   undef $log;


DESCRIPTION

I have used the name space of the Logfile::Base manpage package by Ulrich Pfeifer, as the use of this module closely relates to the processing logfiles.

new
new accepts the following arguments, File, Count, Gzip, Pre, Post, Flock and Dir with only File being mandatory. new will open and lock the file, so you may co-ordinate the processing of the file with rotating it. The file is closed and unlocked when the object is destroyed, so you can do this explicitly by undef'ing the object.

The Pre/Post arguments allow you to pass function references to this method, which you may use as a callback for any processing you want before or after the rotation. For example, you may notify the process writing to the file that it has been rotated.

The Pre function is passed the current filename to be rotated as an argument and the Post function is passed the current filename that was rotated and that file's new filename including any extension added by compression previously.

Both the Pre and Post function references you provide are executed within an eval statement inside the rotate method. If the eval returns an error then the rotate method will croak at that point.

The Signal argument is deprecated by the Post argument.

The Flock argument allows you to specify whether the perl function flock is used to lock the file during the rotation operation. Apparently flock causes problems on some platforms and this option has been added to allow you to control the programs behaviour. By default the file will be locked using flock.

The Persist argument allows you to control whether the program will try and set the current log file ownership and permissions on any new files that may be created by the rotation. In some circumstances the program doing the file rotation may not have sufficient permission to chown on the file. By default the program will try and preserve ownership and permissions.

rotate()
This method will copy the file passed in new to a file of the same name, with a numeric extension and truncate the original file to zero length. The numeric extension will range from 1 up to the value specified by Count, or 7 if none is defined, with 1 being the most recent file. When Count is reached, the older file is discarded in a FIFO (first in, first out) fashion. If the argument Dir was given, all old files will be placed in the specified directory.

The Post function is the last step executed by the rotate method so the return code of rotate will be the return code of the function you proved, or 1 by default.

The copy function is implemented by using the the File::Copy manpage package, but I have had a few people suggest that they would prefer the File::Move manpage. I'm still not decided on this as you would loose data if the move should fail.

Optional Compression

If available rotate will also compress the file with the gzip program or the program passed as the Gzip argument.

You may now also use lib as a value for the Gzip argument. This directs the program to load the Compress::Zlib module, if available and use it do the compression within perl. This avoids the security issues associated with spawning external programs and is the recommended value for this option.

If no argument is defined it will first check to see if the Compress::Zlib module can be loaded then check the perl Config to determine if gzip is available on your system. In this case the gzip must be in your current path to succeed, and accept the -f option.

See the WARNING section below.

Optional Relocation Directory

If you specify an argument for Dir then the file being rotated will be relocated to the directory specified. Along with any other files that may have been rotated previously. If the directory name specified does not exist then it will be created with 0750 permissions. If you wish to have other permissions on the directory then I would recommend you create the directory before using this module.

See the WARNING section below.


WARNING

If a system call is made to gzip this makes this module vulnerable to security problems if a rogue gzip is in your path or gzip has been sabotaged. For this reason a STRONGLY RECOMMEND you DO NOT use this module while you are ROOT.

For a more secure alternative install the Compress::Zlib module and use the lib value for the Gzip argument.

If you specify an argument for Dir and the directory name you pass does not exist, this module will create the directory with permissions 0750.


DEPENDANCIES

See the File::Copy manpage.

If Gzip is being used it must create files with an extension of .gz for the file to be picked by the rotate cycle.


COPYRIGHT

Copyright (c) 1997-99 Paul Gampe. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN ``AS IS'' BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.


SEE ALSO

the File::Copy manpage, the Logfile::Base manpage, flock Changes file for change history and credits for contributions.


RETURN

All functions return 1 on success, 0 on failure.


AUTHOR

Paul Gampe <paulg@apnic.net>

ONS.


SEE ALSO

the File::Copy manpage, the Logfile::Base manpage, flock Changes file for change history and credits for c#warning">WARNING

  • DEPENDANCIES
  • COPYRIGHT
  • SEE ALSO
  • RETURN
  • AUTHOR
  • -->

    NAME

    Logfile::Rotate - Perl module to rotate logfiles.


    SYNOPSIS

       use Logfile::Rotate;
       my $log = new Logfile::Rotate( File   => '/var/adm/syslog/syslog.log', 
                                      Count  => 7,
                                      Gzip  => 'lib',
                                      Post   => sub{ 
                                        open(IN, "/var/run/syslog.pid");
                                        kill("HUP", chomp(<IN>)); }
                                      Dir    => '/var/log/old',
                                      Flock  => 'yes',
                                      Persist => 'yes',
                                    );
       # process log file
       $log->rotate();
       or
    
    
       my $log = new Logfile::Rotate( File  => '/var/adm/syslog', 
                                      Gzip   => '/usr/local/bin/gzip');
    
       # process log file
       $log->rotate();
       undef $log;


    DESCRIPTION

    I have used the name space of the Logfile::Base manpage package by Ulrich Pfeifer, as the use of this module closely relates to the processing logfiles.

    new
    new accepts the following arguments, File, Count, Gzip, Pre, Post, Flock and Dir with only File being mandatory. new will open and lock the file, so you may co-ordinate the processing of the file with rotating it. The file is closed and unlocked when the object is destroyed, so you can do this explicitly by undef'ing the object.

    The Pre/Post arguments allow you to pass function references to this method, which you may use as a callback for any processing you want before or after the rotation. For example, you may notify the process writing to the file that it has been rotated.

    The Pre function is passed the current filename to be rotated as an argument and the Post function is passed the current filename that was rotated and that file's new filename including any extension added by compression previously.

    Both the Pre and Post function references you provide are executed within an eval statement inside the rotate method. If the eval returns an error then the rotate method will croak at that point.

    The Signal argument is deprecated by the Post argument.

    The Flock argument allows you to specify whether the perl function flock is used to lock the file during the rotation operation. Apparently flock causes problems on some platforms and this option has been added to allow you to control the programs behaviour. By default the file will be locked using flock.

    The Persist argument allows you to control whether the program will try and set the current log file ownership and permissions on any new files that may be created by the rotation. In some circumstances the program doing the file rotation may not have sufficient permission to chown on the file. By default the program will try and preserve ownership and permissions.

    rotate()
    This method will copy the file passed in new to a file of the same name, with a numeric extension and truncate the original file to zero length. The numeric extension will range from 1 up to the value specified by Count, or 7 if none is defined, with 1 being the most recent file. When Count is reached, the older file is discarded in a FIFO (first in, first out) fashion. If the argument Dir was given, all old files will be placed in the specified directory.

    The Post function is the last step executed by the rotate method so the return code of rotate will be the return code of the function you proved, or 1 by default.

    The copy function is implemented by using the the File::Copy manpage package, but I have had a few people suggest that they would prefer the File::Move manpage. I'm still not decided on this as you would loose data if the move should fail.

    Optional Compression

    If available rotate will also compress the file with the gzip program or the program passed as the Gzip argument.

    You may now also use lib as a value for the Gzip argument. This directs the program to load the Compress::Zlib module, if available and use it do the compression within perl. This avoids the security issues associated with spawning external programs and is the recommended value for this option.

    If no argument is defined it will first check to see if the Compress::Zlib module can be loaded then check the perl Config to determine if gzip is available on your system. In this case the gzip must be in your current path to succeed, and accept the -f option.

    See the WARNING section below.

    Optional Relocation Directory

    If you specify an argument for Dir then the file being rotated will be relocated to the directory specified. Along with any other files that may have been rotated previously. If the directory name specified does not exist then it will be created with 0750 permissions. If you wish to have other permissions on the directory then I would recommend you create the directory before using this module.

    See the WARNING section below.


    WARNING

    If a system call is made to gzip this makes this module vulnerable to security problems if a rogue gzip is in your path or gzip has been sabotaged. For this reason a STRONGLY RECOMMEND you DO NOT use this module while you are ROOT.

    For a more secure alternative install the Compress::Zlib module and use the lib value for the Gzip argument.

    If you specify an argument for Dir and the directory name you pass does not exist, this module will create the directory with permissions 0750.


    DEPENDANCIES

    See the File::Copy manpage.

    If Gzip is being used it must create files with an extension of .gz for the file to be picked by the rotate cycle.


    COPYRIGHT

    Copyright (c) 1997-99 Paul Gampe. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

    IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN ``AS IS'' BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.


    SEE ALSO

    the File::Copy manpage, the Logfile::Base manpage, flock Changes file for change history and credits for contributions.


    RETURN

    All functions return 1 on success, 0 on failure.


    AUTHOR

    Paul Gampe <paulg@apnic.net>

    ONS.


    SEE ALSO

    the File::Copy manpage, the Logfile::Base manpage, flock Changes file for change history and credits for csyslog.log', Count => 7, Gzip => 'lib', Post => sub{ open(IN, "/var/run/syslog.pid"); kill("HUP", chomp(<IN>)); } Dir => '/var/log/old', Flock => 'yes', Persist => 'yes', );

       # process log file
       $log->rotate();
       or
    
    
       my $log = new Logfile::Rotate( File  => '/var/adm/syslog', 
                                      Gzip   => '/usr/local/bin/gzip');
    
       # process log file
       $log->rotate();
       undef $log;


    DESCRIPTION

    I have used the name space of the Logfile::Base manpage package by Ulrich Pfeifer, as the use of this module closely relates to the processing logfiles.

    new
    new accepts the following arguments, File, Count, Gzip, Pre, Post, Flock and Dir with only File being mandatory. new will open and lock the file, so you may co-ordinate the processing of the file with rotating it. The file is closed and unlocked when the object is destroyed, so you can do this explicitly by undef'ing the object.

    The Pre/Post arguments allow you to pass function references to this method, which you may use as a callback for any processing you want before or after the rotation. For example, you may notify the process writing to the file that it has been rotated.

    The Pre function is passed the current filename to be rotated as an argument and the Post function is passed the current filename that was rotated and that file's new filename including any extension added by compression previously.

    Both the Pre and Post function references you provide are executed within an eval statement inside the rotate method. If the eval returns an error then the rotate method will croak at that point.

    The Signal argument is deprecated by the Post argument.

    The Flock argument allows you to specify whether the perl function flock is used to lock the file during the rotation operation. Apparently flock causes problems on some platforms and this option has been added to allow you to control the programs behaviour. By default the file will be locked using flock.

    The Persist argument allows you to control whether the program will try and set the current log file ownership and permissions on any new files that may be created by the rotation. In some circumstances the program doing the file rotation may not have sufficient permission to chown on the file. By default the program will try and preserve ownership and permissions.

    rotate()
    This method will copy the file passed in new to a file of the same name, with a numeric extension and truncate the original file to zero length. The numeric extension will range from 1 up to the value specified by Count, or 7 if none is defined, with 1 being the most recent file. When Count is reached, the older file is discarded in a FIFO (first in, first out) fashion. If the argument Dir was given, all old files will be placed in the specified directory.

    The Post function is the last step executed by the rotate method so the return code of rotate will be the return code of the function you proved, or 1 by default.

    The copy function is implemented by using the the File::Copy manpage package, but I have had a few people suggest that they would prefer the File::Move manpage. I'm still not decided on this as you would loose data if the move should fail.

    Optional Compression

    If available rotate will also compress the file with the gzip program or the program passed as the Gzip argument.

    You may now also use lib as a value for the Gzip argument. This directs the program to load the Compress::Zlib module, if available and use it do the compression within perl. This avoids the security issues associated with spawning external programs and is the recommended value for this option.

    If no argument is defined it will first check to see if the Compress::Zlib module can be loaded then check the perl Config to determine if gzip is available on your system. In this case the gzip must be in your current path to succeed, and accept the -f option.

    See the WARNING section below.

    Optional Relocation Directory

    If you specify an argument for Dir then the file being rotated will be relocated to the directory specified. Along with any other files that may have been rotated previously. If the directory name specified does not exist then it will be created with 0750 permissions. If you wish to have other permissions on the directory then I would recommend you create the directory before using this module.

    See the WARNING section below.


    WARNING

    If a system call is made to gzip this makes this module vulnerable to security problems if a rogue gzip is in your path or gzip has been sabotaged. For this reason a STRONGLY RECOMMEND you DO NOT use this module while you are ROOT.

    For a more secure alternative install the Compress::Zlib module and use the lib value for the Gzip argument.

    If you specify an argument for Dir and the directory name you pass does not exist, this module will create the directory with permissions 0750.


    DEPENDANCIES

    See the File::Copy manpage.

    If Gzip is being used it must create files with an extension of .gz for the file to be picked by the rotate cycle.


    COPYRIGHT

    Copyright (c) 1997-99 Paul Gampe. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

    IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN ``AS IS'' BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.


    SEE ALSO

    the File::Copy manpage, the Logfile::Base manpage, flock Changes file for change history and credits for contributions.


    RETURN

    All functions return 1 on success, 0 on failure.


    AUTHOR

    Paul Gampe <paulg@apnic.net>

    ONS.


    SEE ALSO

    the File::Copy manpage, the Logfile::Base manpage, flock Changes file for change history and credits for c