Skip to main content

Convert logger f-strings and str.format syntax to printf-style strings

Project description

logo

printf-log-formatter

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)

Motivation

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.

Installation

You have two options for running this pre-commit hook:

Python hook

If you would like to install this using Python, run:

pip install printf-log-formatter

then 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=error

Rust hook

If you're happy to compile the Rust version, you can use:

- repo: https://github.com/sondrelg/printf-log-formatter
  rev: ''
  hooks:
    - id: printf-log-formatter
      args:
        - --log-level=error

I just want to downgrade loggers once

The Rust binary or Python package can also be run directly, like this:

printf-log-formatter $(find . -name "*.py") --log-level error

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

printf_log_formatter-0.3.0-py3-none-win_amd64.whl (1.6 MB view details)

Uploaded Python 3 Windows x86-64

printf_log_formatter-0.3.0-py3-none-win32.whl (1.5 MB view details)

Uploaded Python 3 Windows x86

printf_log_formatter-0.3.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ x86-64

printf_log_formatter-0.3.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.9 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ s390x

printf_log_formatter-0.3.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (3.0 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ppc64le

printf_log_formatter-0.3.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (2.9 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ i686

printf_log_formatter-0.3.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.7 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

printf_log_formatter-0.3.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.7 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

printf_log_formatter-0.3.0-py3-none-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded Python 3 macOS 11.0+ ARM64

printf_log_formatter-0.3.0-py3-none-macosx_10_7_x86_64.whl (1.7 MB view details)

Uploaded Python 3 macOS 10.7+ x86-64

File details

Details for the file printf_log_formatter-0.3.0-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for printf_log_formatter-0.3.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 27c3f053166bfe74e490661e8fe47167b12b8ca4d3066ba13f1ab53d1c7c6788
MD5 30c2cd274dd16e021c88230a767081a1
BLAKE2b-256 f35f22d83a59f2aa7201179d73eacc26ab10846d1e47933d75480e123b1bcf83

See more details on using hashes here.

File details

Details for the file printf_log_formatter-0.3.0-py3-none-win32.whl.

File metadata

File hashes

Hashes for printf_log_formatter-0.3.0-py3-none-win32.whl
Algorithm Hash digest
SHA256 d2fc29f8776121c1477100287c285d4798d310d0547f4573ad3eae23b66549cc
MD5 1f778c0d42f0d9c9b44c3dad129539b6
BLAKE2b-256 ff7fde892947e6860caf2f9fb1185006722870ebddda2cfdefce4602cd9fa0e2

See more details on using hashes here.

File details

Details for the file printf_log_formatter-0.3.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for printf_log_formatter-0.3.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 97d675c90d84b87ecaa48d867b937876d46c66b0d480bf2bae373738fe8a3d17
MD5 778d858852b8f6e2b93f21098d52fb56
BLAKE2b-256 96e15556a067332dbf256e31f93e9bf2c0cd85a3cff6ccf5b2c476bdb51a20df

See more details on using hashes here.

File details

Details for the file printf_log_formatter-0.3.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for printf_log_formatter-0.3.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 af414b2e2d5b78504ace2d5b76b8aaae0afbc894314b56be170d8a052ba81388
MD5 c4eb7a38ed8b400bce4a25b3eb9ebaf6
BLAKE2b-256 bf8e5bd8d4a1a5b209f4de07ad412a47bd7c2cd4fd70d3973657d9bcff6dec34

See more details on using hashes here.

File details

Details for the file printf_log_formatter-0.3.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for printf_log_formatter-0.3.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 d17c0e555ed68249071675f8a86310b251fb84711a1928bfef5d0d14ece2f410
MD5 7e7409b9f5ad403fdc6716cea4d1781f
BLAKE2b-256 88d544cfa70266d7ec5498976e9d9ec9765202cadbd1ff798b391bd1157975c4

See more details on using hashes here.

File details

Details for the file printf_log_formatter-0.3.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for printf_log_formatter-0.3.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b7099fa053a3eae2e9594f18712458b90d8008bc5f942f67bb18f9bc351001cd
MD5 03572eca28f4799589b6a6dd2b0946f6
BLAKE2b-256 b2bc62e5b8e4a8e15b3fcc0a245346f090a0e0a855aaf191dc6c2a62106d1237

See more details on using hashes here.

File details

Details for the file printf_log_formatter-0.3.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for printf_log_formatter-0.3.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 b51bfb73707f47b0dddc215a4660d088be918a250f5040683b724d2a2a9ad4d6
MD5 cf1159b88e70b658110307d34fb65d7f
BLAKE2b-256 d784ada8ce24e04ca4142c5ac4726d9ce284df4cf2ffdc505d6716b3ef950d6d

See more details on using hashes here.

File details

Details for the file printf_log_formatter-0.3.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for printf_log_formatter-0.3.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 300af2cdeafde7e4f0b631d41e82ceb7322a290b8e04c4e4bb35f8334ae9c7e5
MD5 f31ec873549162db6e845ae13e210157
BLAKE2b-256 7d12acae1118f9481758d6981808b0183f92ac6228b63cee315eb6c99a390d3f

See more details on using hashes here.

File details

Details for the file printf_log_formatter-0.3.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for printf_log_formatter-0.3.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c6bb875f2e7ede7467ee59a8f73125cb6361d9b599b8bcf8f9e1f2ca487519ae
MD5 a89655d4623d1eba9b169e5a828a32cf
BLAKE2b-256 a6a76e4449dffad3d095678c9badf1c487d1bc0ea7bba15ea6058f25f7c550a6

See more details on using hashes here.

File details

Details for the file printf_log_formatter-0.3.0-py3-none-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for printf_log_formatter-0.3.0-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 a41bfba0d49dc16675ac9c180c3380903622a4f48d6a537c72394054ed513a35
MD5 d7a73d04030473d37fa2db8f939de306
BLAKE2b-256 e7c989e0cf694ced1721b81a50f7b9265fa7da3ce369833e4065cd2b75bbf22f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page