Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logs: Use journalctl -o with-unit for default logs #3346

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions sos/report/plugins/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class LogsBase(Plugin):
plugin_name = "logs"
profiles = ('system', 'hardware', 'storage')

# The default journal output is syslog-compatible, but it's much
# more useful to have the systemd unit. Related prior art:
# https://github.com/openshift/installer/pull/7371/commits/948df48aada21e47e9bb0d0a53366871aa21b40a
# https://github.com/coreos/coreos-assembler/commit/c931fe0e9aa6b7c20c8279fdce3b6ef448eac8b8
default_format = "with-unit"

def setup(self):
confs = ['/etc/syslog.conf', '/etc/rsyslog.conf']
logs = []
Expand Down Expand Up @@ -64,11 +70,13 @@ def setup(self):
for p in ["/var", "/run"]])
if journal and self.is_service("systemd-journald"):
self.add_journal(since=since, tags=['journal_full', 'journal_all'],
priority=100)
priority=100, output=self.default_format)
self.add_journal(boot="this", since=since,
tags='journal_since_boot')
tags='journal_since_boot',
output=self.default_format)
self.add_journal(boot="last", since=since,
tags='journal_last_boot')
tags='journal_last_boot',
output=self.default_format)
if self.get_option("all_logs"):
self.add_copy_spec([
"/var/log/journal/*",
Expand Down
8 changes: 4 additions & 4 deletions tests/report_tests/plugin_tests/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LogsPluginTest(StageOneReportTest):

def test_journalctl_collections(self):
self.assertFileCollected('sos_commands/logs/journalctl_--disk-usage')
self.assertFileCollected('sos_commands/logs/journalctl_--no-pager_--boot')
self.assertFileCollected('sos_commands/logs/journalctl_-o_with-unit_--no-pager_--boot')

def test_journal_runtime_collected(self):
self.assertFileGlobInArchive('/var/log/journal/*')
Expand Down Expand Up @@ -70,13 +70,13 @@ def pre_sos_setup(self):
sosfd.write(rand[::-1] + '\n')

def test_journal_size_limit(self):
journ = 'sos_commands/logs/journalctl_--no-pager'
journ = 'sos_commands/logs/journalctl_-o_with-unit_--no-pager'
self.assertFileCollected(journ)
jsize = os.stat(self.get_name_in_archive(journ)).st_size
assert jsize <= 20971520, "Collected journal is larger than 20MB (size: %s)" % jsize

def test_journal_tailed_and_linked(self):
tailed = self.get_name_in_archive('sos_strings/logs/journalctl_--no-pager.tailed')
tailed = self.get_name_in_archive('sos_strings/logs/journalctl_-o_with-unit_--no-pager.tailed')
self.assertFileExists(tailed)
journ = self.get_name_in_archive('sos_commands/logs/journalctl_--no-pager')
journ = self.get_name_in_archive('sos_commands/logs/journalctl_-o_with-unit_--no-pager')
assert os.path.islink(journ), "Journal in sos_commands/logs is not a symlink"