hydra/src/lib/Hydra/View/NixLog.pm

39 lines
802 B
Perl
Raw Normal View History

package Hydra::View::NixLog;
use strict;
2021-08-19 16:36:43 -04:00
use warnings;
use base qw/Catalyst::View/;
use Hydra::Helper::CatalystUtils;
sub process {
my ($self, $c) = @_;
my $logPath = $c->stash->{logPath};
$c->response->content_type('text/plain; charset=utf-8');
my $fh = IO::Handle->new();
2017-04-05 17:55:56 +02:00
my $tail = int($c->stash->{tail} // "0");
if ($logPath =~ /\.bz2$/) {
2017-04-05 17:55:56 +02:00
my $doTail = $tail ? " tail -n '$tail' |" : "";
open $fh, "bzip2 -dc < '$logPath' | $doTail" or die;
} else {
2017-04-05 17:55:56 +02:00
if ($tail) {
open $fh, "tail -n '$tail' '$logPath' |" or die;
} else {
open $fh, "<$logPath" or die;
}
}
binmode($fh);
setCacheHeaders($c, 365 * 24 * 60 * 60) if $c->stash->{finished};
$c->response->body($fh);
return 1;
}
1;