X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXLogPrint.pm;h=a6d074a6a64bfd78c768dae4e7388126f537117f;hb=8e14149148baba63ce5ae2b95aacda8ab6dd0d87;hp=ded2f6186a783e27eb865a1eb02d1309efa2c308;hpb=abbcfa7500858a2eba4135b0af5db9f3fca8d68e;p=spider.git diff --git a/perl/DXLogPrint.pm b/perl/DXLogPrint.pm index ded2f618..a6d074a6 100644 --- a/perl/DXLogPrint.pm +++ b/perl/DXLogPrint.pm @@ -8,13 +8,23 @@ package DXLog; +use 5.10.1; + use IO::File; use DXVars; use DXDebug qw(dbg isdbg); use DXUtil; use DXLog; use Julian; -use RingBuf; + + +our $readback = $main::is_win ? 0 : 1; +if ($readback) { + $readback = `which tac`; +} +chomp $readback; +#undef $readback; # yet another reason not to use the cloud! + use strict; @@ -26,11 +36,11 @@ $maxmonths = 36; # # This command outputs a list of n lines starting from time t with $pattern tags # -sub print +sub search { my $fcb = $DXLog::log; - my $from = shift || 0; - my $to = shift || 10; + my $from = shift // 0; + my $to = shift // 10; my $jdate = $fcb->unixtoj(shift); my $pattern = shift; my $who = shift; @@ -42,24 +52,28 @@ sub print my $hint = ""; $who = uc $who if defined $who; + + dbg("from: $from to: $to pattern: $pattern hint: $hint") if isdbg('search'); if ($pattern) { - $hint = "m{\\Q$pattern\\E}i"; + $hint = qq{m{\Q$pattern\E}i}; } else { - $hint = "!m{\\^(?:ann|rcmd|talk|chat)\\^}"; + $hint = q{!m{\^(?:ann|rcmd|talk|chat)\^}}; } if ($who) { $hint .= ' && ' if $hint; - $hint .= 'm{\\Q$who\\E}i'; + $hint .= q{m{\Q$who\E}i}; } $hint = "next unless $hint" if $hint; - $hint .= ";next unless /^\\d+\\^$pattern\\^/" if $pattern; + $hint .= "; next unless m{^\\d+\\^$pattern\\^}i" if $pattern; $hint ||= ""; $eval = qq(while (<\$fh>) { $hint; chomp; - \$ring->write(\$_); + # say "line: \$_"; + push \@in, \$_; + last L1 if \@in >= $tot; } ); if (isdbg('search')) { @@ -70,30 +84,50 @@ sub print $fcb->close; # close any open files my $months; - my $fh = $fcb->open($jdate); - L1: for ($months = 0; $months < $maxmonths && @in < $tot; $months++) { + my $fh; + if ($readback) { + my $fn = $fcb->fn($jdate); + $fh = IO::File->new("$readback $fn |"); + } else { + $fh = $fcb->open($jdate); + } + L1: for ($months = 0; $fh && $months < $maxmonths && @in < $tot; $months++) { my $ref; - my $ring = RingBuf->new($tot); if ($fh) { my @tmp; eval $eval; # do the search on this file return ("Log search error", $@) if $@; - - @in = ($ring->readall, @in); - last L1 if @in >= $tot; } - $fh = $fcb->openprev(); # get the next file - last if !$fh; + if ($readback) { + my $fn = $fcb->fn($jdate->sub(1)); + $fh = IO::File->new("$readback $fn |"); + } else { + $fh = $fcb->openprev(); # get the next file + } } - - @in = splice @in, -$tot, $tot if @in > $tot; - + + unless (@in) { + my $name = $pattern ? $pattern : "log"; + my $s = "$who "|| ''; + return "show/$name: ${s}not found"; + } + + for (sort {$a cmp $b } @in) { + push @out, [ split /\^/ ] + } + + return @out; +} + +sub print +{ + my @out; + + my @in = search(@_); for (@in) { - my @line = split /\^/ ; - push @out, print_item(\@line); - + push @out, print_item($_); } return @out; }