From 8c2b07adeebed573306bc52a26b37b6def75a925 Mon Sep 17 00:00:00 2001 From: Pavel Moravec Date: Tue, 7 Jul 2020 18:57:15 +0200 Subject: [PATCH] [logs] collect also non-persistent journal logs Collect journalctl logs also when journal is configured to store logs in memory only. Further, apply --since option to journal catalog logs. Further, when --all-logs is provided, collect the transient logs in /var/log/journal dir as well. Resolves: #2130 Signed-off-by: Pavel Moravec --- sos/plugins/logs.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/sos/plugins/logs.py b/sos/plugins/logs.py index c92cc1f0..e3b6b884 100644 --- a/sos/plugins/logs.py +++ b/sos/plugins/logs.py @@ -59,13 +59,21 @@ class Logs(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin, CosPlugin): self.add_cmd_output("journalctl --disk-usage") self.add_cmd_output('ls -alRh /var/log/') - journal = os.path.exists("/var/log/journal/") - if journal and self.is_installed("systemd"): + # collect journal logs if: + # - there is some data present, either persistent or runtime only + # - systemd-journald service exists + # otherwise fallback to collecting few well known logfiles directly + journal = any([os.path.exists(p + "/log/journal/") + for p in ["/var", "/run"]]) + if journal and self.is_service("systemd-journald"): self.add_journal(since=since) - self.add_journal(boot="this", catalog=True) - self.add_journal(boot="last", catalog=True) + self.add_journal(boot="this", catalog=True, since=since) + self.add_journal(boot="last", catalog=True, since=since) if self.get_option("all_logs"): - self.add_copy_spec("/var/log/journal/*") + self.add_copy_spec([ + "/var/log/journal/*", + "/run/log/journal/*" + ]) else: # If not using journal if not self.get_option("all_logs"): self.add_copy_spec([ -- 2.26.2