Automatically convert f-strings and str.format() syntax to printf-style strings.
In other words, this syntax
logger.error(f"{1}")
logger.error("{}".format(1))
logger.error("{foo}".format(foo=1))is changed to
logger.error("%s", 1)
logger.error("%s", 1)
logger.error("%s", 1)Why would we want to do this? This article explains it pretty well.
Mainly it's useful for Python projects using Sentry's log integration.
You have two options for running this pre-commit hook:
If you would like to install this using Python, run:
pip install printf-log-formatterthen set the pre-commit hook up using:
- repo: local
hooks:
- id: printf-log-formatter
name: printf-log-formatter
entry: printf-log-formatter
language: system
types: [ python ]
args:
- --log-level=errorIf you're happy to compile the Rust version, you can use:
- repo: https://github.com/snok/printf-log-formatter
rev: ''
hooks:
- id: printf-log-formatter
args:
- --log-level=errorThe Rust binary or Python package can also be run directly, like this:
printf-log-formatter $(find . -name "*.py") --log-level error