diff --git a/README.rst b/README.rst index 0ff34d5..de609df 100644 --- a/README.rst +++ b/README.rst @@ -103,6 +103,11 @@ use_syslog Enable logging to syslog. Default value is False. Example: ``use_syslog=True`` +use_syslog_rfc_format + Enable RFC5424 compliant format for syslog (add APP-NAME before MSG part). + Default value is False. Example: + ``use_syslog_rfc_format=True`` + syslog_log_facility Which syslog facility to use for syslog logging. Valid values include `auth`, `authpriv`, `syslog`, `user0`, `user1`... diff --git a/etc/rootwrap.conf.sample b/etc/rootwrap.conf.sample index a29f501..197b84c 100644 --- a/etc/rootwrap.conf.sample +++ b/etc/rootwrap.conf.sample @@ -16,6 +16,11 @@ exec_dirs=/sbin,/usr/sbin,/bin,/usr/bin # Default value is False use_syslog=False +# Enable RFC5424 compliant format for syslog (add APP-NAME before MSG part) +# Default value is False - no format changes +# TODO(bogdando) remove or use True after existing syslog format deprecation in J +use_syslog_rfc_format=False + # Which syslog facility to use. # Valid values include auth, authpriv, syslog, user0, user1... # Default value is 'syslog' diff --git a/oslo/rootwrap/wrapper.py b/oslo/rootwrap/wrapper.py index e19723d..8177198 100644 --- a/oslo/rootwrap/wrapper.py +++ b/oslo/rootwrap/wrapper.py @@ -78,6 +78,13 @@ class RootwrapConfig(object): else: self.use_syslog = False + # use_syslog_rfc_format + if config.has_option("DEFAULT", "use_syslog_rfc_format"): + self.use_syslog_rfc_format = config.getboolean( + "DEFAULT", "use_syslog_rfc_format") + else: + self.use_syslog_rfc_format = False + def setup_syslog(execname, facility, level): rootwrap_logger = logging.getLogger() diff --git a/tests/test_rootwrap.py b/tests/test_rootwrap.py index 88de79a..c88f0f4 100644 --- a/tests/test_rootwrap.py +++ b/tests/test_rootwrap.py @@ -344,6 +344,7 @@ class RootwrapTestCase(testtools.TestCase): self.assertEqual(c.exec_dirs, []) self.assertFalse(config.use_syslog) + self.assertFalse(config.use_syslog_rfc_format) self.assertEqual(config.syslog_log_facility, logging.handlers.SysLogHandler.LOG_SYSLOG) self.assertEqual(config.syslog_log_level, logging.ERROR) @@ -359,6 +360,12 @@ class RootwrapTestCase(testtools.TestCase): config = wrapper.RootwrapConfig(raw) self.assertTrue(config.use_syslog) + raw.set('DEFAULT', 'use_syslog_rfc_format', 'oui') + self.assertRaises(ValueError, wrapper.RootwrapConfig, raw) + raw.set('DEFAULT', 'use_syslog_rfc_format', 'true') + config = wrapper.RootwrapConfig(raw) + self.assertTrue(config.use_syslog_rfc_format) + raw.set('DEFAULT', 'syslog_log_facility', 'moo') self.assertRaises(ValueError, wrapper.RootwrapConfig, raw) raw.set('DEFAULT', 'syslog_log_facility', 'local0')