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.3.4
  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.3.4.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: lazy_log_formatter-0.3.4.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Linux/6.8.0-45-generic

File hashes

Hashes for lazy_log_formatter-0.3.4.tar.gz
Algorithm Hash digest
SHA256 15740cc5bba09cbb6e748e9789092e98d1ab00d5071c36fe4b87c921433b9d9c
MD5 89c5ca136eadadd943c8ac81a3adb711
BLAKE2b-256 003be1cd4032b366657519904f42e986ef4a370162559ad1bdbab19f30fc6bb4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lazy_log_formatter-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f315e60b9a78c061943bcce4355b4ba22fcfde7efd8dd09d24bef91be84559a6
MD5 729f1f38ce722f1c86de1b4b785ad847
BLAKE2b-256 5942bafbf6d9c2108831b05350e1fa30d7f6c36cf48335d0cd509f565d4975b3

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