Skip to main content

A pre-commit script to make log lines lazzier

Project description

Lazy log formatter

Pre-commit hook to automatically detect and convert f-strings in Python code used in log calls to lazy log calls, following W1203 Pylint rule:

https://pylint.readthedocs.io/en/stable/user_guide/messages/warning/logging-fstring-interpolation.html

Usage

To use with pre-commit, add the following to your .pre-commit-config.yaml:

- repo: https://github.com/dmar1n/lazy-log-formatter
  rev: 0.4.1
  hooks:
    - id: lazy-log-formatter
    args: ['--fix']

Options

  • --fix: Automatically fix f-strings used in log calls to lazy log calls.

Examples

If the --fix option is used, the hook will convert f-strings in log calls to lazy log calls, as follows:

# Before
logger.info(f'Hello {name}')

# After
logger.info('Hello %s', name)
# Before
logger.info(f'Hello {name} {surname}')

# After
logger.info('Hello %s %s', name, surname)

Project details


Download files

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

Source Distribution

lazy_log_formatter-0.4.1.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

lazy_log_formatter-0.4.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file lazy_log_formatter-0.4.1.tar.gz.

File metadata

  • Download URL: lazy_log_formatter-0.4.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for lazy_log_formatter-0.4.1.tar.gz
Algorithm Hash digest
SHA256 f1f292310dc7969a1e61aa810f0127c312a7beb377fe9837970538c25f1c7ad1
MD5 e21bf09494ade4965f63ea669567d9bd
BLAKE2b-256 c9a78bcb623683e11d4680dffbd29edb5b8e27567ab6d3ca071f396fe7288035

See more details on using hashes here.

Provenance

The following attestation bundles were made for lazy_log_formatter-0.4.1.tar.gz:

Publisher: release.yaml on dmar1n/lazy-log-formatter

Attestations:

File details

Details for the file lazy_log_formatter-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for lazy_log_formatter-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a752b8606039d19de3b7916e3449bcd58dc0f99456f5bfc12810085fe4e1fba2
MD5 d4499d760fb2fa067fd1f8c6adebbc8c
BLAKE2b-256 888951073a48a87fa7bba125a9eef0a12b0bead2d93ed86b7f90043a295364f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for lazy_log_formatter-0.4.1-py3-none-any.whl:

Publisher: release.yaml on dmar1n/lazy-log-formatter

Attestations:

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