remove string formatting in log statements

Bug #1234283 reported by Dolph Mathews
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Identity (keystone)
Fix Released
Low
Lars Butler

Bug Description

This is based on comments in: https://review.openstack.org/#/c/46822/

The python logging module supports passing args and kwargs to populate strings AFTER the logging level has been checked. That means that string formatting can be avoided if it's unnecessary due to the current logging level.

So, any instance of:

  LOG.debug(_('The entity, %s, was not found.') % entity)

Can be replaced with:

  LOG.debug(_('The entity, %s, was not found.'), entity)

Which will be slightly more performant when debug logging is disabled.

Dolph Mathews (dolph)
tags: added: low-hanging-fruit
tags: added: performance
Changed in keystone:
assignee: nobody → Lars Butler (lars-butler)
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to keystone (master)

Fix proposed to branch: master
Review: https://review.openstack.org/54381

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to keystone (master)

Reviewed: https://review.openstack.org/54381
Committed: http://github.com/openstack/keystone/commit/e3e5122f4e70dad64bf202bc379d8e235ce2ea84
Submitter: Jenkins
Branch: master

commit e3e5122f4e70dad64bf202bc379d8e235ce2ea84
Author: Lars Butler <email address hidden>
Date: Tue Oct 29 17:23:45 2013 +0100

    Style improvements to logging format strings

    Added the following improvements:

    * Use the logging API to handle formatting of message args, which
      potentially prevents us from having to do a bunch of redundant string
      formatting for logging statements which occur below the runtime's
      logging level. For example, in many places `LOG.debug('foo %s' % bar)`
      has been replaced with `LOG.debug('foo %s', bar)`.
    * Similarly, this change also removes a few redundant repr() and str()
      calls. For example: `LOG.error('foo %r', repr(bar))` ->
      `LOG.error('foo %r', bar)`, and the same for %s/str().
    * One logging statement included some unnecessary escaping in the log
      message string (e.g., 'foo is a \'bar\'', which was replaced with
      "foo is a 'bar'").
    * Added some missing message translation calls.

    Change-Id: I9080aebdf0ce0e719949d009e0ab85bfc6be8646
    Closes-Bug: #1234283

Changed in keystone:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in keystone:
milestone: none → icehouse-1
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in keystone:
milestone: icehouse-1 → 2014.1
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.