When I write a message to a Python logger, and the message has parameters, I now write it like this:
logger.info("Person %s cuts at %f.", person.name, location)
This is the old way of string-formatting; the new way would be:
logger.info("Person {} cuts at {}.", person.name, location)
but this raises an error. I could convert the message into a single string like so:
logger.info("Person {} cuts at {}.".format(person.name, location))
However, in this case the string is generated even when the log message should not be displayed, e.g. when the logging level is WARNING. This is wasteful.
My question is: how can I write a log message that does not automatically expand its parameters, while using the new syntax for string formatting?