From: Dietmar Maurer Date: Fri, 18 Apr 2014 05:20:12 +0000 (+0200) Subject: dump_logfile: add filter regex X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=eb7e5538615974e1e72a92c8e5812781374df25d;hp=5ca176e356fe6835127c24ac24bc2bbf09899ada dump_logfile: add filter regex --- diff --git a/data/PVE/Tools.pm b/data/PVE/Tools.pm index 7448183..5b30aed 100644 --- a/data/PVE/Tools.pm +++ b/data/PVE/Tools.pm @@ -932,7 +932,7 @@ sub split_args { } sub dump_logfile { - my ($filename, $start, $limit) = @_; + my ($filename, $start, $limit, $filter) = @_; my $lines = []; my $count = 0; @@ -948,12 +948,25 @@ sub dump_logfile { $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);