--- trunk/lib/Frey/Shell/Log.pm 2008/12/25 12:43:13 901 +++ trunk/lib/Frey/Shell/Log.pm 2008/12/25 14:01:40 902 @@ -4,7 +4,7 @@ extends 'Frey'; with 'Frey::Web'; -use DateTimeX::Easy; +use DateTime::Locale; has log_command => ( is => 'rw', @@ -23,6 +23,17 @@ isa => 'Str', ); +# we don't use DateTime because it's huge overhead for every log line +my $month2nr; +{ + my @months = @{ DateTime::Locale->load('en_US')->month_abbreviations }; + warn "# months ", join(',',@months); + + foreach my $i ( 0 .. $#months ) { + $month2nr->{ lc($months[$i]) } = $i + 1; + } +} + sub as_sponge { my ($self) = @_; @@ -31,37 +42,35 @@ my @rows; - my $from = DateTimeX::Easy->parse( $self->from_datetime ) if $self->from_datetime; - my $to = DateTimeX::Easy->parse( $self->to_datetime ) if $self->to_datetime; - - sub date_time { - my $dt = shift || return; - $dt->ymd . ' ' . $dt->hms; - } + my $from = $self->from_datetime; + my $to = $self->to_datetime; my $stats = { - from => date_time( $from ), - to => date_time( $to ), + from => $from, + to => $to, }; warn "# stats ",$self->dump( $stats ); + my $yyyy = (localtime(time))[5] + 1900; + open(my $fh, '-|', $cmd) || die "can't open pipe to $cmd $!"; while(<$fh>) { chomp; if ( m{^(\w\w\w) (\d\d) (\d\d:\d\d:\d\d) (.+)} ) { my $message = $4; - my $dt = DateTimeX::Easy->parse("2008-$1-$2 $3"); - if ( $from && $dt < $from ) { + my $mm = $month2nr->{lc($1)} || die "month $1 unknown"; + my $dt = sprintf("%04d-%02d-%02d %s", $yyyy, $mm, $2, $3, $4); + if ( $from && $dt lt $from ) { $stats->{before_from}++; next; } - if ( $to && $dt > $to ) { + if ( $to && $dt gt $to ) { $stats->{after_to}++; next; } - push @rows, [ date_time( $dt ), $message ]; + push @rows, [ $dt, $message ]; $stats->{rows}++; } else { warn "# skip $_\n";