Thank you for starting this discussion and Doug, thank you for clarifying. Your explanation below helps a lot!


On 12/22/2014 12:13 PM, Doug Hellmann wrote:
On Dec 22, 2014, at 1:05 PM, John Griffith <> wrote:

On Mon, Dec 22, 2014 at 10:03 AM, Ben Nemec <> wrote:
On 12/22/2014 09:42 AM, John Griffith wrote:
Lately (on the Cinder team at least) there's been a lot of
disagreement in reviews regarding the proper way to do LOG messages
correctly.  Use of '%' vs ',' in the formatting of variables etc.

We do have the oslo i18n guidelines page here [1], which helps a lot
but there's some disagreement on a specific case here.  Do we have a
set answer on:'some message: v1=%(v1)s v2=%(v2)s') % {'v1': v1, 'v2': v2})

vs'some message: v1=%(v1)s v2=%(v2)s'), {'v1': v1, 'v2': v2})
This is the preferred way.

Note that this is just a multi-variable variation on
and the reasoning discussed there applies.

I'd be curious why some people prefer the % version because to my
knowledge that's not recommended even for untranslated log messages.
Not sure if it's that anybody has a preference as opposed to an
interpretation, notice the recommendation for multi-vars in raise:

raise ValueError(_('some message: v1=%(v1)s v2=%(v2)s') % {'v1': v1, 'v2': v2})
It’s really not related to translation as much as the logging API itself.

With the exception, you want to initialize the ValueError instance with a 
proper message as soon as you throw it because you don’t know what the calling 
code might do with it. Therefore you use string interpolation inline.

When you call into  the logging subsystem, your call might be ignored based on 
the level of the message and the logging configuration. By letting the logging 
code do the string interpolation, you potentially skip the work of serializing 
variables to strings for messages that will be discarded, saving time and 

These “rules” apply whether your messages are being translated or not, so even 
for debug log messages you should write:

   LOG.debug(‘some message: v1=%(v1)s v2=%(v2)s’, {‘v1’: v1, ‘v2’: v2})

It's always fun when one person provides a -1 for the first usage; the
submitter changes it and another reviewer gives a -1 and says, no it
should be the other way.

I'm hoping maybe somebody on the olso team can provide an
authoritative answer and we can then update the example page
referenced in [1] to clarify this particular case.



OpenStack-dev mailing list

OpenStack-dev mailing list
OpenStack-dev mailing list

OpenStack-dev mailing list

OpenStack-dev mailing list

Reply via email to