loguru
loguru copied to clipboard
Support python 3.14 Template Strings
Writing
logger.debug(f"Expensive/large object = {obj}")
Is not ideal for performance reasons due to the eager evaluation of the format string (see https://docs.astral.sh/ruff/rules/logging-f-string/ for a more thorough explanation).
This is why loguru has implemented its own formatting via parameters. The README states:
### Modern string formatting using braces style
Loguru favors the much more elegant and powerful `{}` formatting over `%`, logging functions are actually equivalent to `str.format()`.
`logger.info("If you're using Python {}, prefer {feature} of course!", 3.6, feature="f-strings")`
With Python 3.14, we can provide the same functionality, by supporting Template Strings. The above example from the readme could then read:
version = 3.14
feature = "t-strings"
logger.info(t"If you're using Python {version}, prefer {feature} of course!")