[pmg-devel] [PATCH common v4] return whole log file if limit is 0

Daniel Tschlatscher d.tschlatscher at proxmox.com
Wed Nov 23 15:52:10 CET 2022


The dump_logfile now returns the whole log file if the limit parameter
is set to 0. This must be done explicitely though, as in the case of
'limit' being undefined, the default as before, 50 will be used.

Signed-off-by: Daniel Tschlatscher <d.tschlatscher at proxmox.com>
---
Changes from v3:
* NEW patch

This patch also affects the API endpoints for:
* the ceph log file
* replication log files
* firewall Guest and Host log files

It does not change how they behave in the GUI though, as all of the
corresponding API calls there do not specify a 'limit=0' parameter.
In fact, none of them specify any limit, therefore, the default value
of 50 still applies.

 src/PVE/Tools.pm | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index eb81b96..6072eb7 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -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--;
 	}
     }
 
-- 
2.30.2





More information about the pmg-devel mailing list