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
?