3

I like str.format - the syntax is clean, and it's feature rich. I use it almost everywhere.

Unfortunately logging uses the old string interpolation (% operator). If given a str.format style string, it just fails.

>>> logging.error("foo {}", 1)
[...]
TypeError: not all arguments converted during string formatting

Of course, I can just format beforehand:

>>> logging.error("foo {}".format(1))

But this is not ideal for larger objects with lots of debug logging calls, for performance reasons.

Is there a way to properly use str.format style with logging?

loopbackbee
  • 21,962
  • 10
  • 62
  • 97
  • `str.format` : https://docs.python.org/2/library/stdtypes.html#str.format. I wonder whether there is any option like you mentioned above for `str.format` – Suku Nov 15 '16 at 01:47

0 Answers0