[pve-devel] [RFC common 1/1] add Tools::print_journal
Dominik Csapak
d.csapak at proxmox.com
Mon May 13 14:49:19 CEST 2019
which uses the new journalreader tool instead of journalctl,
with different parameters and a different return format:
array of strings with a start/end cursor
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/PVE/Tools.pm | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 4dd073f..4195cde 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -54,6 +54,8 @@ O_TMPFILE
my $pvelogdir = "/var/log/pve";
my $pvetaskdir = "$pvelogdir/tasks";
+my $JOURNALREADER = "/usr/bin/journalreader";
+
mkdir $pvelogdir;
mkdir $pvetaskdir;
@@ -1235,6 +1237,29 @@ sub dump_logfile {
return ($count, $lines);
}
+# returns the given journal range/entries as an array
+# the first and last entries are cursors where the user can continue
+sub read_journal {
+ my ($since, $until, $lastentries, $startcursor, $endcursor) = @_;
+
+ my $lines = [];
+
+ my $parser = sub {
+ push @$lines, shift;
+ };
+
+ my $cmd = [$JOURNALREADER];
+ push @$cmd, '-n', $lastentries if $lastentries;
+ push @$cmd, '-b', $since if $since;
+ push @$cmd, '-e', $until if $until;
+ push @$cmd, '-f', $startcursor if $startcursor;
+ push @$cmd, '-t', $endcursor if $endcursor;
+
+ run_command($cmd, outfunc => $parser);
+
+ return $lines;
+}
+
sub dump_journal {
my ($start, $limit, $since, $until, $service) = @_;
--
2.11.0
More information about the pve-devel
mailing list