}
sub dump_logfile {
- my ($filename, $start, $limit) = @_;
+ my ($filename, $start, $limit, $filter) = @_;
my $lines = [];
my $count = 0;
$limit = 50 if !$limit;
my $line;
- while (defined($line = <$fh>)) {
- next if $count++ < $start;
- next if $limit <= 0;
- chomp $line;
- push @$lines, { n => $count, t => $line};
- $limit--;
+
+ if ($filter) {
+ # duplicate code, so that we do not slow down normal path
+ while (defined($line = <$fh>)) {
+ next if $line !~ m/$filter/;
+ next if $count++ < $start;
+ next if $limit <= 0;
+ chomp $line;
+ push @$lines, { n => $count, t => $line};
+ $limit--;
+ }
+ } else {
+ while (defined($line = <$fh>)) {
+ next if $count++ < $start;
+ next if $limit <= 0;
+ chomp $line;
+ push @$lines, { n => $count, t => $line};
+ $limit--;
+ }
}
close($fh);