Nir Soffer has uploaded a new change for review.
Change subject: logUtils: Process SimpleLogAdapter's context once ......................................................................
logUtils: Process SimpleLogAdapter's context once
We used to format SimpleLogAdapter's contextual information on each logging call. This generates lot of garbage adding unneeded cost for logging calls. Format the context once when creating an instance.
Change-Id: I32bbafb6ef60d118e2341f081d036107406a43a4 Signed-off-by: Nir Soffer nsoffer@redhat.com --- M vdsm/logUtils.py 1 file changed, 20 insertions(+), 5 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/52/48552/1
diff --git a/vdsm/logUtils.py b/vdsm/logUtils.py index 5caa167..6675faa 100644 --- a/vdsm/logUtils.py +++ b/vdsm/logUtils.py @@ -89,12 +89,27 @@ # and warn are the same. I need to reimplement it here. :( warn = logging.LoggerAdapter.warning
+ def __init__(self, logger, context): + """ + Initialize an adapter with a logger and a dict-like object which + provides contextual information. The contextual informatnion is + prepended to each log message. + + This adapter:: + + self.log = SimpleLogAdapter(self.log, {"key": "value"}) + self.log.debug("Message") + + Would produce this message:: + + "key=value::Message" + """ + self.logger = logger + items = "".join("%s=%s" % (k, v) for k, v in context.iteritems()) + self.prefix = items + "::" + def process(self, msg, kwargs): - result = '' - for key, value in self.extra.iteritems(): - result += '%s=`%s`' % (key, value) - result += '::%s' % msg - return (result, kwargs) + return self.prefix + msg, kwargs
class TracebackRepeatFilter(logging.Filter):
gerrit-hooks has posted comments on this change.
Change subject: logUtils: Process SimpleLogAdapter's context once ......................................................................
Patch Set 1:
* Update tracker: IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.6', 'ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Nir Soffer has posted comments on this change.
Change subject: logUtils: Process SimpleLogAdapter's context once ......................................................................
Patch Set 1: Verified+1
Piotr Kliczewski has posted comments on this change.
Change subject: logUtils: Process SimpleLogAdapter's context once ......................................................................
Patch Set 1:
(1 comment)
https://gerrit.ovirt.org/#/c/48552/1//COMMIT_MSG Commit Message:
Line 8: Line 9: We used to format SimpleLogAdapter's contextual information on each Line 10: logging call. This generates lot of garbage adding unneeded cost for Line 11: logging calls. Format the context once when creating an instance. Line 12: Please provide an example of new logging message using context information. Line 13: Change-Id: I32bbafb6ef60d118e2341f081d036107406a43a4
Francesco Romani has posted comments on this change.
Change subject: logUtils: Process SimpleLogAdapter's context once ......................................................................
Patch Set 1: Code-Review+1
strong +1 for the idea, the implementation looks ok.
vdsm-patches@lists.fedorahosted.org