summaryrefslogtreecommitdiffstats
path: root/nova/openstack
diff options
context:
space:
mode:
authorSean Dague <sdague@linux.vnet.ibm.com>2012-07-30 14:55:58 -0400
committerSean Dague <sdague@linux.vnet.ibm.com>2012-07-30 15:06:16 -0400
commit367300c1566950c16157bc4ae2955e2ef3616fb5 (patch)
tree5dcd210b74387e257a91c1c83776c80c8247bf73 /nova/openstack
parent9b61fdf34bee6ad9d8e28a32c4c30df243b02443 (diff)
downloadnova-367300c1566950c16157bc4ae2955e2ef3616fb5.tar.gz
nova-367300c1566950c16157bc4ae2955e2ef3616fb5.tar.xz
nova-367300c1566950c16157bc4ae2955e2ef3616fb5.zip
sync openstack-common log changes with nova
don't throw exceptions if %(color)s tag is used fixes bug #1030078 If the log format strings include the %(color)s key in them and you enable file logging, your log files won't work, and instead you'll see exceptions on the console as the default python log handler doesn't support that keyword. This approach stubs out the extra keywords to be empty strings to avoid the KeyError. Tests are also added to demonstrate the KeyError as defined behavior, and test that color codes can be passed. Change-Id: I24b2f45dd5a38b27b8cc5a70e0084d367e218172
Diffstat (limited to 'nova/openstack')
-rw-r--r--nova/openstack/common/log.py38
1 files changed, 21 insertions, 17 deletions
diff --git a/nova/openstack/common/log.py b/nova/openstack/common/log.py
index 228f39dd1..eac2a8ac8 100644
--- a/nova/openstack/common/log.py
+++ b/nova/openstack/common/log.py
@@ -66,13 +66,13 @@ log_opts = [
help='prefix each line of exception output with this format'),
cfg.ListOpt('default_log_levels',
default=[
- 'amqplib=WARN',
- 'sqlalchemy=WARN',
- 'boto=WARN',
- 'suds=INFO',
- 'keystone=INFO',
- 'eventlet.wsgi.server=WARN'
- ],
+ 'amqplib=WARN',
+ 'sqlalchemy=WARN',
+ 'boto=WARN',
+ 'suds=INFO',
+ 'keystone=INFO',
+ 'eventlet.wsgi.server=WARN'
+ ],
help='list of logger=LEVEL pairs'),
cfg.BoolOpt('publish_errors',
default=False,
@@ -89,7 +89,7 @@ log_opts = [
default='[instance: %(uuid)s] ',
help='If an instance UUID is passed with the log message, '
'format it like this'),
- ]
+]
generic_log_opts = [
@@ -105,7 +105,7 @@ generic_log_opts = [
cfg.StrOpt('logfile_mode',
default='0644',
help='Default file mode used when creating log files'),
- ]
+]
CONF = cfg.CONF
@@ -208,9 +208,9 @@ class JSONFormatter(logging.Formatter):
def formatException(self, ei, strip_newlines=True):
lines = traceback.format_exception(*ei)
if strip_newlines:
- lines = [itertools.ifilter(lambda x: x,
- line.rstrip().splitlines())
- for line in lines]
+ lines = [itertools.ifilter(
+ lambda x: x,
+ line.rstrip().splitlines()) for line in lines]
lines = list(itertools.chain(*lines))
return lines
@@ -252,9 +252,9 @@ class PublishErrorsHandler(logging.Handler):
CONF.list_notifier_drivers):
return
notifier.api.notify(None, 'error.publisher',
- 'error_notification',
- notifier.api.ERROR,
- dict(error=record.msg))
+ 'error_notification',
+ notifier.api.ERROR,
+ dict(error=record.msg))
def handle_exception(type, value, tb):
@@ -405,8 +405,12 @@ class LegacyFormatter(logging.Formatter):
def format(self, record):
"""Uses contextstring if request_id is set, otherwise default."""
- if 'instance' not in record.__dict__:
- record.__dict__['instance'] = ''
+ # NOTE(sdague): default the fancier formating params
+ # to an empty string so we don't throw an exception if
+ # they get used
+ for key in ('instance', 'color'):
+ if key not in record.__dict__:
+ record.__dict__[key] = ''
if record.__dict__.get('request_id', None):
self._fmt = CONF.logging_context_format_string