From 14088fb6e43676b2bfbbcd96bc78740ee862c550 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Fri, 27 Jul 2012 17:22:58 -0400 Subject: don't throw exceptions if %(color)s tag is used fixed 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: Ia5dbaee9c530e243e2121667c8a54e6f9d66e1e7 --- openstack/common/log.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'openstack') diff --git a/openstack/common/log.py b/openstack/common/log.py index 8a368a1..5f0478f 100644 --- a/openstack/common/log.py +++ b/openstack/common/log.py @@ -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 -- cgit