A log message is formatted before the call, even when the level is turned off
What it finds
logger.debug(f"state {state}") builds the string on every call, also when debug messages are turned off, and log handlers that group messages by their template see a different message each time. logger.debug("state %s", state) leaves the formatting to the logger, which does it only for messages it emits. Reported are calls of debug, info, warning, error, critical and exception on loggers whose message is an f-string, a % formatting or a .format call.
From the rule's source, eager_log_formatting.rs.
import logging logger = logging.getLogger(__name__) def run(state): logger.debug(f"state {state}")tx0 reports: the message is formatted with an f-string logger.info("state %s" % state)tx0 reports: the message is formatted with % logger.warning("state {}".format(state))tx0 reports: the message is formatted with format logger.debug("state %s", state) print(f"state {state}") Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:eager-log-formatting" = "note"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:eager-log-formatting] reason="..."tx0 explain tx0/python:eager-log-formatting shows the same in the terminal. Found a false positive? Report it.