3 ms·
The only reason it makes sense to do this is if the overhead of doing the string formatting is way higher than the enabled test: if logger.isEnabledFor(loggi
by compressedgas 2y ago
The only reason it makes sense to do this is if the overhead of doing the string formatting is way higher than the enabled test:
if logger.isEnabledFor(logging.DEBUG):
logger.debug(f"Processing cache entry for key: {key}")
But the logger already does this filtering by log level as the implementation of the logging.Logger.debug method already has this check:
if self.isEnabledFor(DEBUG):
The implementation already defers string formatting until after this check if you pass the format string and the arguments.
I think the recommendation should be to never use f-strings with logger method calls and instead use a format string and pass the interpolation arguments.