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>
This commit is contained in:
Bogdan Dobrelya 2014-02-24 10:52:16 +02:00
parent 8ef33015c6
commit 1649ed1725
4 changed files with 24 additions and 0 deletions

View File

@ -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`...

View File

@ -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'

View File

@ -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()

View File

@ -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')