1010from sos .report .plugins import Plugin , PluginOpt , IndependentPlugin , CosPlugin
1111
1212
13+ JOURNAL_SINCE_LONG_DESC = (
14+ "Bounds the journalctl text capture by passing the value to "
15+ "`journalctl --since`, which accepts any systemd.time(7) "
16+ "expression (e.g. '-7days', '-24hours', '2 hours ago', "
17+ "'yesterday', '2026-04-19', '2026-04-19 08:00:00'). Use "
18+ "'all' (or leave empty) for no bound. Plugin default 'all', "
19+ "overridden to '-7days' by the bundled conf files. See "
20+ "`man systemd.time` and `man journalctl`."
21+ )
22+
23+
1324class LogsBase (Plugin ):
1425
1526 short_desc = 'System logs'
1627
1728 plugin_name = "logs"
1829 profiles = ('system' , 'hardware' , 'storage' )
1930
31+ option_list = [
32+ PluginOpt (name = "journal-since" , default = "all" , val_type = str ,
33+ desc = ("journalctl --since value, e.g. '-7days', "
34+ "or 'all' for no bound" ),
35+ long_desc = JOURNAL_SINCE_LONG_DESC )
36+ ]
37+
2038 def setup (self ):
2139 rsyslog = 'etc/rsyslog.conf'
2240 confs = ['/etc/syslog.conf' , rsyslog ]
@@ -56,6 +74,9 @@ def setup(self):
5674 self .add_cmd_output ("journalctl --disk-usage" )
5775 self .add_dir_listing ('/var/log' , recursive = True )
5876
77+ since_raw = (self .get_option ("journal-since" ) or "" ).strip ()
78+ since_arg = (None if since_raw .lower () in ("" , "all" ) else since_raw )
79+
5980 # collect journal logs if:
6081 # - there is some data present, either persistent or runtime only
6182 # - systemd-journald service exists
@@ -64,9 +85,11 @@ def setup(self):
6485 for p in ["/var" , "/run" ])
6586 if journal and self .is_service ("systemd-journald" ):
6687 self .add_journal (tags = ['journal_full' , 'journal_all' ],
67- priority = 100 )
68- self .add_journal (boot = "this" , tags = 'journal_since_boot' )
69- self .add_journal (boot = "last" , tags = 'journal_last_boot' )
88+ priority = 100 , since = since_arg )
89+ self .add_journal (boot = "this" , tags = 'journal_since_boot' ,
90+ since = since_arg )
91+ self .add_journal (boot = "last" , tags = 'journal_last_boot' ,
92+ since = since_arg )
7093 if self .get_option ("all_logs" ):
7194 self .add_copy_spec ([
7295 "/var/log/journal/*" ,
@@ -104,7 +127,7 @@ class IndependentLogs(LogsBase, IndependentPlugin):
104127
105128
106129class CosLogs (LogsBase , CosPlugin ):
107- option_list = [
130+ option_list = LogsBase . option_list + [
108131 PluginOpt (name = "log-days" , default = 3 ,
109132 desc = "the number of days logs to collect" )
110133 ]
0 commit comments