diff options
author | Bogdan Dobrelya <bdobrelia@mirantis.com> | 2014-02-24 10:52:16 +0200 |
---|---|---|
committer | Bogdan Dobrelya <bdobrelia@mirantis.com> | 2014-02-25 19:18:13 +0200 |
commit | 1649ed17252160b5f50bd7e500f9b243a14bd8e7 (patch) | |
tree | 7215456c1e2ed0a73bfb1f412671d9744272848c | |
parent | 8ef33015c607d0356a2fca47f39028384dd366af (diff) | |
download | oslo-rootwrap-1649ed17252160b5f50bd7e500f9b243a14bd8e7.tar.gz |
To honor RFC5424 add use_syslog_rfc_format config option
Since the rootwrap code was graduated to a separate library,
This change completes one from oslo-incubator:
Backport 'ident' from python 3.3 for Oslo's SysLogHandler
(with commit 79e8a9a08daf563aa8a8d9280c9a6a27dcafc8f2)
To honor RFC5424 add use_syslog_rfc_format config option
(default False, would be deprecated in J after existing
syslog format deprecation) which adds APP-NAME to syslog message
before MSG part to reflect application or service name.
Usable only with use_syslog, otherwise ignored.
During J, the default logging format for syslog should be changed
to always provide APP-NAME, thus use_syslog_rfc_format could be
deprecated in J as well.
Closes-bug: #904307
Change-Id: Icff9db07d543738e092a8826e8a0d2e4b213fc38
Signed-off-by: Bogdan Dobrelya <bdobrelia@mirantis.com>
-rw-r--r-- | README.rst | 5 | ||||
-rw-r--r-- | etc/rootwrap.conf.sample | 5 | ||||
-rw-r--r-- | oslo/rootwrap/wrapper.py | 7 | ||||
-rw-r--r-- | tests/test_rootwrap.py | 7 |
4 files changed, 24 insertions, 0 deletions
@@ -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') |