Sync latest oslo-incubator log for debug fixes

This patch pulls in the changes in openstack/common/log.py that
fix the problems that popped up after we removed _() from
around LOG.debug messages.  The change in log ensures that any
text that is not of six.text_type is converted to six.text_type.

Current HEAD in OSLO:
---------------------
commit 759bd8791ec6a4b0e89f649a4179d177530e7536
Merge: 71d072f 631f880
Author: Jenkins <jenkins@review.openstack.org>
Date:   Wed Aug 13 13:37:27 2014 +0000

Merge "Set keystonemiddleware and routes.middleware to log on WARN level"
---------------------

Additional changes being merged (newest to oldest):
---------------------
759bd879 -
Merge "Set keystonemiddleware and routes.middleware to log on WARN level
71d072f1 -
Merge "Except socket.error if syslog isn't running"
37c00918 -
Add unicode coercion of logged messages to ContextFormatter
66144135 -
Correct coercion of logged message to unicode
1188d88a -
Except socket.error if syslog isn't running
ac995bec -
Fix E126 pep8 errors

Note that this change required an update to config.sample due to change
759bd879 -  Merge "Set keystonemiddleware and routes.middleware to log
on WARN level"

Change-Id: I4b849981c65300b327076d68fbf8601d46ec61f0
Closes-Bug: 1348244
This commit is contained in:
Jay S. Bryant 2014-08-13 12:16:49 -05:00
parent 03884b3d64
commit ca810742e0
2 changed files with 32 additions and 23 deletions

View File

@ -33,6 +33,7 @@ import logging
import logging.config
import logging.handlers
import os
import socket
import sys
import traceback
@ -126,7 +127,8 @@ DEFAULT_LOG_LEVELS = ['amqp=WARN', 'amqplib=WARN', 'boto=WARN',
'qpid=WARN', 'sqlalchemy=WARN', 'suds=INFO',
'oslo.messaging=INFO', 'iso8601=WARN',
'requests.packages.urllib3.connectionpool=WARN',
'urllib3.connectionpool=WARN', 'websocket=WARN']
'urllib3.connectionpool=WARN', 'websocket=WARN',
"keystonemiddleware=WARN", "routes.middleware=WARN"]
log_opts = [
cfg.StrOpt('logging_context_format_string',
@ -300,11 +302,10 @@ class ContextAdapter(BaseLoggerAdapter):
self.warn(stdmsg, *args, **kwargs)
def process(self, msg, kwargs):
# NOTE(mrodden): catch any Message/other object and
# coerce to unicode before they can get
# to the python logging and possibly
# cause string encoding trouble
if not isinstance(msg, six.string_types):
# NOTE(jecarey): If msg is not unicode, coerce it into unicode
# before it can get to the python logging and
# possibly cause string encoding trouble
if not isinstance(msg, six.text_type):
msg = six.text_type(msg)
if 'extra' not in kwargs:
@ -429,12 +430,12 @@ def set_defaults(logging_context_format_string=None,
# later in a backwards in-compatible change
if default_log_levels is not None:
cfg.set_defaults(
log_opts,
default_log_levels=default_log_levels)
log_opts,
default_log_levels=default_log_levels)
if logging_context_format_string is not None:
cfg.set_defaults(
log_opts,
logging_context_format_string=logging_context_format_string)
log_opts,
logging_context_format_string=logging_context_format_string)
def _find_facility_from_conf():
@ -483,18 +484,6 @@ def _setup_logging_from_conf(project, version):
for handler in log_root.handlers:
log_root.removeHandler(handler)
if CONF.use_syslog:
facility = _find_facility_from_conf()
# 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()
if logpath:
filelog = logging.handlers.WatchedFileHandler(logpath)
@ -553,6 +542,20 @@ def _setup_logging_from_conf(project, version):
else:
logger.setLevel(level_name)
if CONF.use_syslog:
try:
facility = _find_facility_from_conf()
# TODO(bogdando) use the format provided by RFCSysLogHandler
# after existing syslog format deprecation in J
if CONF.use_syslog_rfc_format:
syslog = RFCSysLogHandler(facility=facility)
else:
syslog = logging.handlers.SysLogHandler(facility=facility)
log_root.addHandler(syslog)
except socket.error:
log_root.error('Unable to add syslog handler. Verify that syslog'
'is running.')
_loggers = {}
@ -622,6 +625,12 @@ class ContextFormatter(logging.Formatter):
def format(self, record):
"""Uses contextstring if request_id is set, otherwise default."""
# NOTE(jecarey): If msg is not unicode, coerce it into unicode
# before it can get to the python logging and
# possibly cause string encoding trouble
if not isinstance(record.msg, six.text_type):
record.msg = six.text_type(record.msg)
# store project info
record.project = self.project
record.version = self.version

View File

@ -766,7 +766,7 @@
#logging_exception_prefix=%(asctime)s.%(msecs)03d %(process)d TRACE %(name)s %(instance)s
# List of logger=LEVEL pairs. (list value)
#default_log_levels=amqp=WARN,amqplib=WARN,boto=WARN,qpid=WARN,sqlalchemy=WARN,suds=INFO,oslo.messaging=INFO,iso8601=WARN,requests.packages.urllib3.connectionpool=WARN,urllib3.connectionpool=WARN,websocket=WARN
#default_log_levels=amqp=WARN,amqplib=WARN,boto=WARN,qpid=WARN,sqlalchemy=WARN,suds=INFO,oslo.messaging=INFO,iso8601=WARN,requests.packages.urllib3.connectionpool=WARN,urllib3.connectionpool=WARN,websocket=WARN,keystonemiddleware=WARN,routes.middleware=WARN
# Enables or disables publication of error events. (boolean
# value)