]> git.proxmox.com Git - pve-common.git/commitdiff
dump logfile: return whole log file if limit is 0
authorDaniel Tschlatscher <d.tschlatscher@proxmox.com>
Wed, 23 Nov 2022 14:52:10 +0000 (15:52 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 24 Nov 2022 16:12:02 +0000 (17:12 +0100)
The dump_logfile now returns the whole log file if the limit
parameter is set to 0. This must be done explicitly though, as in the
case of 'limit' being undefined, the default as before, 50 will be
used.

Signed-off-by: Daniel Tschlatscher <d.tschlatscher@proxmox.com>
src/PVE/Tools.pm

index eb81b96b7f876b0a7be463033a847dd708ad1c63..6072eb736afaf51f6b2631158f7f1e5e36189ee1 100644 (file)
@@ -1278,9 +1278,10 @@ sub dump_logfile {
        return ($count, $lines);
     }
 
-    $start = 0 if !$start;
-    $limit = 50 if !$limit;
+    $start = $start // 0;
+    $limit = $limit // 50;
 
+    my $read_until_end = ($limit == 0) ? 1 : 0;
     my $line;
 
     if ($filter) {
@@ -1288,18 +1289,22 @@ sub dump_logfile {
        while (defined($line = <$fh>)) {
            next if $line !~ m/$filter/;
            next if $count++ < $start;
-           next if $limit <= 0;
+           if (!$read_until_end) {
+               next if $limit <= 0;
+               $limit--;
+           }
            chomp $line;
            push @$lines, { n => $count, t => $line};
-           $limit--;
        }
     } else {
        while (defined($line = <$fh>)) {
            next if $count++ < $start;
-           next if $limit <= 0;
+           if (!$read_until_end) {
+               next if $limit <= 0;
+               $limit--;
+           }
            chomp $line;
            push @$lines, { n => $count, t => $line};
-           $limit--;
        }
     }