From: Erik Wasser < erik dot wasser at iquer dot net > To: A.Ford@ford-mason.co.uk Subject: Re: gzip patch for cronolog Date: Sat, 5 Jul 2003 14:47:41 +0200 On Saturday 05 July 2003 14:55, you wrote: > >I've written a gzip patch for cronosplit. If you run "cronosplit" > > with the parameter "--gzip" every written logfile is packed > > on-the-fly via the perl modul IO::Zlib. Are you in interessested in > > the ~60 lines of patch for cronolog 1.6.2? > > > >Thanks for your work. > > Sure. I'll take a look at it and most probably first put it in the > patches directory and then incorporate it into the versions of > cronolog that I am working on. Here's the patch. I would like it to see it on your homepage. B-) You need the IO::Zlib (IO-functionality) and the Compress::Zlib (zlib-functionality) for the patch. The main reason for writing it is the hard space you can save by using it like this: % zmergelog *.gz | cronosplit --zlib --template=newlogs/access-%Y-%m.log The old scrambled logfiles are unpacked on the fly, resorted and saved packed to disc. Very fine. B-) -- So long... Fuzz diff -ru cronolog-1.6.2-orig/src/cronosplit.in cronolog-1.6.2-zlib/src/cronosplit.in --- cronolog-1.6.2-orig/src/cronosplit.in 1999-12-27 16:52:52.000000000 +0100 +++ cronolog-1.6.2-zlib/src/cronosplit.in 2003-07-05 13:20:03.000000000 +0200 @@ -119,12 +119,16 @@ "debug", \$debug, "verbose", \$verbose, "help", \$print_help, + "zlib", \$zlib, "version", \$print_version) and ($print_help or $print_version or $template)) or $print_help++; $verbose++ if $debug; # --debug implies --verbose +if ($zlib) { + require IO::Zlib; +} # If version number requested, print it and exit @@ -160,6 +164,8 @@ --print-invalid print invalid log-file entries --help print this help, then exit --version print version number, then exit + --zlib use zlib for compression of the + written logfiles EOS exit(0); } @@ -260,8 +266,9 @@ return $handle if defined($handle = $OpenHandles{$file}); # See if we already have too many files opened - - if (($#HandlesInUse + 1) >= $MaxHandles) + # (only if we're not using zlib, reopening a packed file + # wouldn't be a good idea) + if (!$zlib && ($#HandlesInUse + 1) >= $MaxHandles) { local($oldkey) = shift @HandlesInUse; # close the oldest $handle = $OpenHandles{$oldkey}; @@ -275,7 +282,15 @@ make_dirs($file); - if (open($handle, ">>$file")) + my $return; + + if (!$zlib) { + $return = open($handle, ">>$file"); + } else { + $return = $handle = IO::Zlib->new("$file", "wb9"); + } + + if ($return) { push(@HandlesInUse, $file); $OpenHandles{$file} = $handle;