diff options
| author | Sean Dague <sdague@linux.vnet.ibm.com> | 2012-07-27 17:22:58 -0400 |
|---|---|---|
| committer | Sean Dague <sdague@linux.vnet.ibm.com> | 2012-07-27 17:22:58 -0400 |
| commit | 14088fb6e43676b2bfbbcd96bc78740ee862c550 (patch) | |
| tree | bd8690329b653e1e68c2308ff5edc3a2fd2a3126 /openstack/common | |
| parent | c11a0d419f658fcec716c2d32ee10f17ecbfb2b9 (diff) | |
| download | oslo-14088fb6e43676b2bfbbcd96bc78740ee862c550.tar.gz oslo-14088fb6e43676b2bfbbcd96bc78740ee862c550.tar.xz oslo-14088fb6e43676b2bfbbcd96bc78740ee862c550.zip | |
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
Diffstat (limited to 'openstack/common')
| -rw-r--r-- | openstack/common/log.py | 8 |
1 files changed, 6 insertions, 2 deletions
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 |
