* Read logs using logContents function in stead of handling it everywhere separately.

This commit is contained in:
Rob Vermaas 2012-06-26 12:00:18 +02:00
parent 0701cd0da8
commit a2f56ce574
3 changed files with 40 additions and 33 deletions

View file

@ -47,11 +47,9 @@ sub view_build : Chained('build') PathPart('') Args(0) {
$c->stash->{pathHash} = $c->stash->{available} ? queryPathHash($build->outpath) : undef; $c->stash->{pathHash} = $c->stash->{available} ? queryPathHash($build->outpath) : undef;
my $pipestart;
if (!$build->finished && $build->busy) { if (!$build->finished && $build->busy) {
my $logfile = $build->logfile; my $logfile = $build->logfile;
$pipestart = cat_log_command($logfile); $c->stash->{logtext} = logContents($logfile);
$c->stash->{logtext} = `$pipestart` if defined $logfile && -e $logfile;
} }
if ($build->finished && $build->iscachedbuild) { if ($build->finished && $build->iscachedbuild) {
@ -62,8 +60,7 @@ sub view_build : Chained('build') PathPart('') Args(0) {
(my $lastBuildStep) = $build->buildsteps->search({},{order_by => "stepnr DESC", rows => 1}); (my $lastBuildStep) = $build->buildsteps->search({},{order_by => "stepnr DESC", rows => 1});
my $path = defined $lastBuildStep ? $lastBuildStep->logfile : "" ; my $path = defined $lastBuildStep ? $lastBuildStep->logfile : "" ;
if ($build->finished && ($build->buildstatus == 1 || $build->buildstatus == 6) && !($path eq "") && -f $lastBuildStep->logfile) { if ($build->finished && ($build->buildstatus == 1 || $build->buildstatus == 6) && !($path eq "") && -f $lastBuildStep->logfile) {
$pipestart = cat_log_command($path); my $logtext = logContents($path, 50);
my $logtext = `$pipestart | tail -n 50`;
$c->stash->{logtext} = removeAsciiEscapes($logtext); $c->stash->{logtext} = removeAsciiEscapes($logtext);
} }
@ -126,10 +123,9 @@ sub showLog {
notFound($c, "Log file $path no longer exists.") unless -f $fallbackpath; notFound($c, "Log file $path no longer exists.") unless -f $fallbackpath;
$path = $fallbackpath; $path = $fallbackpath;
my $pipestart = ($path =~ /.bz2$/ ? "cat $path | bzip2 -d" : "cat $path") ;
if (!$mode) { if (!$mode) {
# !!! quick hack # !!! quick hack
my $pipestart = ($path =~ /.bz2$/ ? "cat $path | bzip2 -d" : "cat $path") ;
my $pipeline = $pipestart my $pipeline = $pipestart
. " | nix-log2xml | xsltproc " . $c->path_to("xsl/mark-errors.xsl") . " -" . " | nix-log2xml | xsltproc " . $c->path_to("xsl/mark-errors.xsl") . " -"
. " | xsltproc " . $c->path_to("xsl/log2html.xsl") . " - | tail -n +2"; . " | xsltproc " . $c->path_to("xsl/log2html.xsl") . " - | tail -n +2";
@ -139,7 +135,7 @@ sub showLog {
} }
elsif ($mode eq "raw") { elsif ($mode eq "raw") {
$c->stash->{'plain'} = { data => (scalar `$pipestart`) || " " }; $c->stash->{'plain'} = { data => (scalar logContents($path)) || " " };
$c->forward('Hydra::View::Plain'); $c->forward('Hydra::View::Plain');
} }
@ -149,12 +145,12 @@ sub showLog {
$c->stash->{url} = $url; $c->stash->{url} = $url;
$c->stash->{reload} = !$c->stash->{build}->finished && $c->stash->{build}->busy; $c->stash->{reload} = !$c->stash->{build}->finished && $c->stash->{build}->busy;
$c->stash->{title} = ""; $c->stash->{title} = "";
$c->stash->{contents} = (scalar `$pipestart | tail -n 50`) || " "; $c->stash->{contents} = (scalar logContents($path, 50)) || " ";
$c->stash->{template} = 'plain-reload.tt'; $c->stash->{template} = 'plain-reload.tt';
} }
elsif ($mode eq "tail") { elsif ($mode eq "tail") {
$c->stash->{'plain'} = { data => (scalar `$pipestart | tail -n 50`) || " " }; $c->stash->{'plain'} = { data => (scalar logContents($path, 50)) || " " };
$c->forward('Hydra::View::Plain'); $c->forward('Hydra::View::Plain');
} }

View file

@ -236,6 +236,18 @@ sub getLatestSuccessfulViewResult {
return undef; return undef;
} }
sub logContents {
my ($path, $tail) = @_;
my $cmd;
if ($path =~ /.bz2$/) {
$cmd = "cat $path | bzip2 -d";
$cmd = $cmd . " | tail -$tail" if defined $tail;
}
else {
$cmd = defined $tail ? "tail -$tail $path" : "cat $path";
}
return `$cmd` if -e $path;
}
sub removeAsciiEscapes { sub removeAsciiEscapes {
my ($logtext) = @_; my ($logtext) = @_;

View file

@ -157,8 +157,7 @@ sub sendEmailNotification {
$inputsTable->load(@lines); $inputsTable->load(@lines);
my $loglines = 50; my $loglines = 50;
my $logfile = $build->logfile; my $logtext = logContents($build->logfile, $loglines);
my $logtext = defined $logfile && -e $logfile ? `tail -$loglines $logfile` : "No logfile available.\n";
$logtext = removeAsciiEscapes($logtext); $logtext = removeAsciiEscapes($logtext);
my $body = "Hi,\n" my $body = "Hi,\n"