Sync log.py from oslo

This change syncs log.py from oslo-incubator 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.

Since the rootwrap code was graduating to a separate library,
so the rootwrap related change should just go into oslo.rootwrap
and when oslo.rootwrap is released, nova will pull in the library.

Change-Id: I6018c7322314a4b57052be1ec0fc5fa437069f44
Closes-bug: 904307
This commit is contained in:
liyingjun 2014-01-15 14:43:36 +08:00
parent b939e13f28
commit 35ee11438d
2 changed files with 40 additions and 4 deletions

View File

@ -1651,9 +1651,17 @@
# Deprecated group/name - [DEFAULT]/logdir
#log_dir=<None>
# Use syslog for logging. (boolean value)
# Use syslog for logging. Existing syslog format is DEPRECATED
# during I, and then will be changed in J to honor RFC5424
# (boolean value)
#use_syslog=false
# (Optional) Use syslog rfc5424 format for logging. If
# enabled, will add APP-NAME (RFC5424) before the MSG part of
# the syslog message. The old format without APP-NAME is
# deprecated in I, and will be removed in J. (boolean value)
#use_syslog_rfc_format=false
# syslog facility to receive log lines (string value)
#syslog_log_facility=LOG_USER

View File

@ -115,7 +115,18 @@ logging_cli_opts = [
'--log-file paths'),
cfg.BoolOpt('use-syslog',
default=False,
help='Use syslog for logging.'),
help='Use syslog for logging. '
'Existing syslog format is DEPRECATED during I, '
'and then will be changed in J to honor RFC5424'),
cfg.BoolOpt('use-syslog-rfc-format',
# TODO(bogdando) remove or use True after existing
# syslog format deprecation in J
default=False,
help='(Optional) Use syslog rfc5424 format for logging. '
'If enabled, will add APP-NAME (RFC5424) before the '
'MSG part of the syslog message. The old format '
'without APP-NAME is deprecated in I, '
'and will be removed in J.'),
cfg.StrOpt('syslog-log-facility',
default='LOG_USER',
help='syslog facility to receive log lines')
@ -457,6 +468,17 @@ def _find_facility_from_conf():
return facility
class RFCSysLogHandler(logging.handlers.SysLogHandler):
def __init__(self, *args, **kwargs):
self.binary_name = _get_binary_name()
super(RFCSysLogHandler, self).__init__(*args, **kwargs)
def format(self, record):
msg = super(RFCSysLogHandler, self).format(record)
msg = self.binary_name + ' ' + msg
return msg
def _setup_logging_from_conf():
log_root = getLogger(None).logger
for handler in log_root.handlers:
@ -464,8 +486,14 @@ def _setup_logging_from_conf():
if CONF.use_syslog:
facility = _find_facility_from_conf()
syslog = logging.handlers.SysLogHandler(address='/dev/log',
facility=facility)
# TODO(bogdando) use the format provided by RFCSysLogHandler
# after existing syslog format deprecation in J
if CONF.use_syslog_rfc_format:
syslog = RFCSysLogHandler(address='/dev/log',
facility=facility)
else:
syslog = logging.handlers.SysLogHandler(address='/dev/log',
facility=facility)
log_root.addHandler(syslog)
logpath = _get_log_file_path()