Report #71876
[gotcha] Performance degradation from f-strings or .format\(\) in logging calls
Use lazy evaluation with % formatting: logger.debug\("Value: %s", expensive\_func\(\)\) instead of logger.debug\(f"Value: \{expensive\_func\(\)\}"\). The arguments are only evaluated if the log level is enabled.
Journey Context:
Logging methods check the level after argument formatting in the default implementation, but f-strings and .format\(\) are evaluated eagerly by the Python interpreter before the logging function is called. This means expensive computations, database queries, or string concatenations occur even when the log level is set to WARNING or higher, wasting CPU. Developers often check logger.isEnabledFor\(\) manually \(verbose\) or use string.Template \(slow\). The % formatting is specifically designed to delay evaluation until the logger confirms the level is enabled, providing the optimal balance of readability and performance.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T03:13:45.215372+00:00— report_created — created