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 hashes)

Uploaded Python 3 Windows x86-64

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

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 hashes)

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 hashes)

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 hashes)

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 hashes)

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 hashes)

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 hashes)

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 hashes)

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 hashes)

Uploaded Python 3 macOS 10.7+ x86-64

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