What is the recommended method for logging variables using Python logging
, and why is it better?
Old-style interpolation:
apple = "green"
logger.debug("apple is %s", apple)
or
New-style .format()
logger.debug("apple is {}".format(apple))
I have heard that interpolation is preferred, because it only evaluates the string if it's going to be printed, but I haven’t verified if it actually matters.