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