Is there any difference between these two calls:
import logging
logging.getLogger().debug('test: %i' % 42)
and
logging.getLogger().debug('test: {}'.format(42))
Where we assume 42
is replaced by some long computation (say 7.5 million years of computation) when it is cast to a string that produces a final answer of 42.
Is the first approach lazily evaluated in case logging is set to debug?
f-strings
which are faster than these methods, check: stackoverflow.com/questions/43123408/f-strings-in-python-3-6logging
module gets involved in the process at all. You probably want to pass the format string and its parameters as separate parameters to.debug()
, so that it actually does the formatting - I assume that it only does this if the message isn't going to be filtered out, but I'm not 100% sure of that.if logging.getLogger().isEnabledFor(logging.DEBUG): …
. From your comments on the answers, though, it sounds like you don't need that.