From 5fc26034c590e6d79a2eb25f1c1dba1a84c8c49b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 22 Jul 2003 20:52:25 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=1773 --- html/ops/show_log.php | 4 +++- sched/grep_logs | 39 +++++++++++++++++++++++++++++++++++++-- sched/main.C | 2 +- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/html/ops/show_log.php b/html/ops/show_log.php index 7e097fba1b..55ac761863 100644 --- a/html/ops/show_log.php +++ b/html/ops/show_log.php @@ -13,6 +13,7 @@ $f = $_GET["f"]; $s = $_GET["s"]; + $l = (int)$_GET["l"]; if (!$f || !preg_match("/^ *([a-z_*]+[.](log|out) *)+$/", $f)) { $f = '*.log'; @@ -27,11 +28,12 @@ echo "
"; echo " Regexp: "; echo " Files: "; + echo " Lines: (positive for head, negative for tail)"; echo "
"; echo 'Hint: Example greps: "RESULT#106876", "26fe99aa_25636_00119.wu_1", "WU#8152", "too many errors", "2003-07-17", "CRITICAL"
'; - passthru("cd $log_dir && ../bin/grep_logs -html '$s' $f 2>&1"); + passthru("cd $log_dir && ../bin/grep_logs -html -l $l '$s' $f 2>&1 $lines"); page_tail(); } ?> diff --git a/sched/grep_logs b/sched/grep_logs index e3c86b78c8..b3d88eeeae 100755 --- a/sched/grep_logs +++ b/sched/grep_logs @@ -7,11 +7,16 @@ use strict; use warnings; my $html = 0; +my $lines = 0; die unless @ARGV; if ($ARGV[0] eq '-html') { shift; $html = 1; } +if ($ARGV[0] eq '-l') { + shift; + $lines = shift; +} my $s = shift; die unless defined $s; @@ -24,27 +29,57 @@ if ($s =~ /\d$/) { my $prev_file = ''; +my $nlines = 0; +my @slines = (); + +sub printline($) +{ + ++$nlines; + if ($lines < 0) { + # tail - need to store all lines first + push(@slines, $_[0]); + } else { + return if ($lines > 0 && $nlines > $lines) ; + print $_[0]; + } +}; +sub finish_printlines() +{ + if ($lines < 0) { + if (scalar(@slines) > -$lines) { + @slines = @slines[$#slines+$lines+1..$#slines]; + } + print @slines; + } + $nlines = 0; + @slines = (); +} + if ($html) { print "
"; }
 while () {
     chomp;
     if (/$s/) {
         if ($ARGV ne $prev_file) {
+            finish_printlines();
             $prev_file = $ARGV;
             if ($html) {
                 print "

$ARGV

";
             } else {
                 print "\n\n$ARGV:\n";
             }
+            $nlines = 0;
         }
         my $n = sprintf("%05d", $.);
+                
         if ($html) {
             s%.*debug.*%$&%i;
             s%.*(critical|error).*%$&%i;
             s%$s%$&%g if $s;
-            print "$n  $_\n";
+            printline "$n  $_\n";
         } else {
-            print "  $n: $_\n";
+            printline "  $n: $_\n";
         }
     }
 }
+finish_printlines();
 if ($html) { print "
"; } diff --git a/sched/main.C b/sched/main.C index ede37d9302..c93eedf360 100644 --- a/sched/main.C +++ b/sched/main.C @@ -48,7 +48,7 @@ static const char* STDERR_FILENAME = "../log/cgi.log"; #define REQ_FILE_PREFIX "boinc_req_" #define REPLY_FILE_PREFIX "boinc_reply_" -bool use_files = true; // use disk files for req/reply msgs (for debugging) +bool use_files = false; // use disk files for req/reply msgs (for debugging) DB_PROJECT gproject; CONFIG config;