Gregor Hoffleit wrote...
> While cronolog seems to be able to handle ErrorLog format, cronosplit
> won't split ErrorLog files: cronosplit rejects every line in an error
> log file (try "cronosplit --print-invalid").
>
> It would be really nice if this asymmetry could be resolved.
In order to improve the quality of the package, I uploaded an NMU that
also included a fix for this bug. The diff is attached. Note that
020_cronosplit_HMS.diff has been incorporated into this one, remove it
from debian/patches before rebuilding.
> Also, it might be helpful if the documentation would stress that
> cronolog and cronosplit have different limitations.
I am sorry, limitations of what kind?
Christoph
diff -urN cronolog-1.6.2.orig/src/cronosplit.in cronolog-1.6.2/src/cronosplit.in
--- cronolog-1.6.2.orig/src/cronosplit.in 2004-04-06 07:03:32.000000000 +0200
+++ cronolog-1.6.2/src/cronosplit.in 2006-06-04 12:14:19.000000000 +0200
@@ -70,26 +70,38 @@
# (splitlog is part of the wwwstat package,
# see <http://www.ics.uci.edu/pub/websoft/wwwstat/>)
+require 5.8.0;
use Getopt::Long;
+use Time::Local;
+use POSIX qw(strftime);
-$program = 'cronosplit';
-$version = '@VERSION@';
+use strict;
-# Parameters
+my $program = 'cronosplit';
+my $version = '@VERSION@';
+
+# Programs
-$MaxHandles = 50;
-$DirMode = 0775;
+my $ZCAT = '/bin/zcat';
+my $BZCAT = '/usr/bin/bzcat';
+
+# Parameters
+my $MaxHandles = 50;
+my $DirMode = 0775;
# Patterns for log file entries (Common Log Format) and timestamps
-$log_entry_pattern = "^(\\S+) (\\S+) ([^[]+) \\[([^]]*)] \"([^\"]*)\" (\\S+)
(\\S+)(.*)";
-$timestamp_pattern = "^([
0-3]?\\d)/([A-Za-z]+)/(\\d{4}):(\\d\\d):(\\d\\d):(\\d\\d) [+ -]\\d{1,4}";
+my $access_log_entry_pattern = "^(\\S+) (\\S+) ([^[]+) \\[([^]]*)]
\"([^\"]*)\" (\\S+) (\\S+)(.*)";
+my $access_timestamp_pattern = "^([
0-3]?\\d)/([A-Za-z]+)/(\\d{4}):(\\d\\d):(\\d\\d):(\\d\\d) [+ -]\\d{1,4}";
+
+my $error_log_entry_pattern = "^\\[([^]]*)] \\[([^]]*)] (\\S+)(.*)";
+my $error_timestamp_pattern = "^[A-Z][a-z]{2} ([A-Z][a-z]{2}) ([0-3]?\\d)
(\\d\\d):(\\d\\d):(\\d\\d) (\\d{4})";
# An associative array of month names and abbreviations
-%month = (Jan => 1, January => 1,
+my %month = (Jan => 1, January => 1,
Feb => 2, February => 2,
Mar => 3, March => 3,
Apr => 4, April => 4,
@@ -102,15 +114,21 @@
Nov => 11, November => 11,
Dec => 12, December => 12);
[EMAIL PROTECTED] = ("", "January", "February", "March", "April", "May", "June",
- "July", "August", "September", "October", "November", "December");
[EMAIL PROTECTED] = ("", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
-
[EMAIL PROTECTED] = ("Sunday", "Monday", "Tuesday", "Wednesday",
- "Thursday", "Friday", "Saturday");
[EMAIL PROTECTED] = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
+# Variables
+
+my $file;
+my $outfile;
+my $template;
+my $debug;
+my $verbose;
+my $PrintInvalids;
+my $print_help;
+my $print_version;
+my $handle;
+
+my %OpenHandles = ();
+my @HandlesInUse = ();
# Process options
@@ -170,7 +188,6 @@
push(@ARGV, "-") unless @ARGV;
-
FILE:
foreach $file (@ARGV) {
if ($file eq "-") {
@@ -180,7 +197,20 @@
elsif ($file =~ /\.gz$/) {
print STDERR "opening \"$file\"\n" if $verbose;
- if (!open(INFILE, "zcat $file|")) {
+ if (!open(INFILE, "-|", $ZCAT, $file)) {
+ print STDERR "cannot open \"$file\"\n";
+ next FILE;
+ }
+ }
+ elsif ($file =~ /\.bz2$/) {
+ if (! -x $BZCAT)
+ {
+ print STDERR "Cannot process \"$file\", install bzip2 first.\n";
+ next FILE;
+ }
+ print STDERR "opening \"$file\"\n" if $verbose;
+
+ if (!open(INFILE, "-|", $BZCAT, $file)) {
print STDERR "cannot open \"$file\"\n";
next FILE;
}
@@ -188,7 +218,7 @@
else {
print STDERR "opening \"$file\"\n" if $verbose;
- if (! open(INFILE, $file)) {
+ if (! open(INFILE, "<$file")) {
print STDERR "cannot open \"$file\"\n";
next FILE;
}
@@ -201,32 +231,34 @@
LINE:
while (<INFILE>)
{
- my($host, $ident, $authuser, $timestamp,
- $request, $status, $bytes, $trailer) = /$log_entry_pattern/;
-
- if (!($host && $ident && $authuser && $timestamp && $request &&
$status))
- {
- if ($PrintInvalids) { print STDERR "$.:$saveline"; }
- next LINE;
- }
-
- if ($timestamp =~ /$timestamp_pattern/)
+ my ($timestamp, $time_t);
+ if (/$access_log_entry_pattern/)
{
- ($day, $mon, $year, $hour, $min, $sec) = ($1, $2, $3, $4, $5, $6);
- }
- else
+ $timestamp = $4;
+ if ($timestamp =~ /$access_timestamp_pattern/)
+ {
+ # 1:day 2:month 3:year 4:hour 5:minute 6:second
+ $time_t = eval { timelocal($6, $5, $4, $1, $month{$2} - 1, $3 -
1900) };
+ }
+ }
+ elsif (/$error_log_entry_pattern/)
+ {
+ $timestamp = $1;
+ if ($timestamp =~ /$error_timestamp_pattern/)
+ {
+ # 1:month 2:day 3:hour 4:minute 5:second 6:year
+ $time_t = eval { timelocal($5, $4, $3, $2, $month{$1} - 1, $6 -
1900) };
+ }
+ }
+ if (!defined ($time_t))
{
- if ($PrintInvalids) { print STDERR "$.:$saveline"; }
+ if ($PrintInvalids) { print STDERR "$.:$_"; }
next LINE;
}
- next LINE unless defined($outfile = &get_handle($template,
- $day, $mon, $year,
- $hour, $min, $sec));
-
- print($outfile $host, ' ', $ident, ' ', $authuser,
- ' [', $timestamp, '] "', $request, '" ',
- $status, ' ', $bytes, $trailer, "\n");
+ next LINE unless defined($outfile = &get_handle($template, $time_t));
+
+ print($outfile $_);
}
close(INFILE);
@@ -238,22 +270,14 @@
sub get_handle
{
- my($template, $day, $mon, $year, $hour, $min, $sec) = @_;
- $mon = $month{$mon};
+ my($template, $time_t) = @_;
# Determine the filename from the template and time
my($file) = $template;
- $file =~ s/%Y/sprintf("%04d", $year)/eg;
- $file =~ s/%m/sprintf("%02d", $mon)/eg;
- $file =~ s/%d/sprintf("%02d", $day)/eg;
- $file =~ s/%b/$mmm[$mon]/g;
- $file =~ s/%B/$month[$mon]/g;
- $file =~ s/%H/sprintf("%02d", $hour)/eg;
- $file =~ s/%M/sprintf("%02m", $min)/eg;
- $file =~ s/%S/sprintf("%02m", $sec)/eg;
-
+ my(@time) = localtime($time_t);
+ $file =~ s/(%[a-zA-Z%])/strftime($1, @time)/eg;
# See if we already have it open and ready to write
@@ -263,7 +287,7 @@
if (($#HandlesInUse + 1) >= $MaxHandles)
{
- local($oldkey) = shift @HandlesInUse; # close the oldest
+ my ($oldkey) = shift @HandlesInUse; # close the oldest
$handle = $OpenHandles{$oldkey};
delete $OpenHandles{$oldkey};
close $handle;
@@ -271,7 +295,7 @@
# Finally, try to open and remember a new handle for this pathkey
- $handle = ++$NextHandle;
+ undef $handle;
make_dirs($file);
@@ -321,7 +345,7 @@
# Check each directory on the path
- foreach $i (0 .. $#path)
+ foreach my $i (0 .. $#path)
{
$path = $abs . join("/", (@path[0 .. $i]));
print(STDERR "Testing $path\n") if $debug;