Difference between revisions of "Enhanced-context-logger-oslo"
(Created page with "== Blueprint Design for ([https://blueprints.launchpad.net/oslo/+spec/enhanced-context-logger enhanced-context-logger]) == === Problem Statement === Currently, the logger does...") |
(→Blueprint Design for (enhanced-context-logger)) |
||
Line 5: | Line 5: | ||
=== Proposed Design === | === Proposed Design === | ||
The idea is to introduce a placeholder for sub-contextual information. The logic would run based on the presence of such placeholder. The classes that would be enhanced in the process would be the '''openstack.common.log.ContextAdapter''' and '''openstack.common.log.ContextFormatter''' | The idea is to introduce a placeholder for sub-contextual information. The logic would run based on the presence of such placeholder. The classes that would be enhanced in the process would be the '''openstack.common.log.ContextAdapter''' and '''openstack.common.log.ContextFormatter''' | ||
+ | |||
+ | ==== Proposed modification to the ContextAdapter ==== | ||
+ | Add a placeholder named "sub_context" within the "extra", and if found unroll it into the "extra" like below: | ||
+ | |||
+ | extra.update({"version": self.version}) | ||
+ | '''if extra.get('sub_context', None):''' | ||
+ | '''sub_context = extra.get('sub_context', None)''' | ||
+ | '''for k in sub_context:''' | ||
+ | '''extra.update({k:sub_context[k]})''' | ||
+ | extra['extra'] = extra.copy() | ||
+ | |||
+ | |||
+ | ==== Proposed modification to the ContextFormatter ==== | ||
+ | |||
+ | self._fmt += " " + CONF.logging_debug_format_suffix | ||
+ | '''if record.__dict__.get('sub_context', None):''' | ||
+ | '''sub_context = record.__dict__.get('sub_context', None)''' | ||
+ | '''for k in sub_context:''' | ||
+ | '''self._fmt += " [" + k + ":%(" + k + ")s]"''' |
Revision as of 21:38, 4 February 2014
Contents
Blueprint Design for (enhanced-context-logger)
Problem Statement
Currently, the logger does not provide any means to the drivers or consumers to add any additional contextual information other than the one that has been baked into the logger e.g. instanceId. The blueprint is going to add the flexibility to the logger, so that if needed the consumer of the logger could add some contextual data that can then show up in the logs without changing the individual log statements throughout the code.
Proposed Design
The idea is to introduce a placeholder for sub-contextual information. The logic would run based on the presence of such placeholder. The classes that would be enhanced in the process would be the openstack.common.log.ContextAdapter and openstack.common.log.ContextFormatter
Proposed modification to the ContextAdapter
Add a placeholder named "sub_context" within the "extra", and if found unroll it into the "extra" like below:
extra.update({"version": self.version}) if extra.get('sub_context', None): sub_context = extra.get('sub_context', None) for k in sub_context: extra.update({k:sub_context[k]}) extra['extra'] = extra.copy()
Proposed modification to the ContextFormatter
self._fmt += " " + CONF.logging_debug_format_suffix if record.__dict__.get('sub_context', None): sub_context = record.__dict__.get('sub_context', None) for k in sub_context: self._fmt += " [" + k + ":%(" + k + ")s]"