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 to printf-style logging 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.5.0
  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)

Current limitations

Only works with the native Python logging module. Other libraries, such as loguru, do not support lazy calls.

For loguru, see Lazy evaluation of expensive functions:

logger.opt(lazy=True).debug("If sink level <= DEBUG: {x}", x=lambda: expensive_function(2**64))

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lazy_log_formatter-0.5.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lazy_log_formatter-0.5.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for lazy_log_formatter-0.5.0.tar.gz
Algorithm Hash digest
SHA256 991ff4ce335854583589c9aa23bed328bdfa33274db88d2ada01e987d912913c
MD5 674d99af6e9532a42b3f72ee715dc014
BLAKE2b-256 0a0e372cd8926a6cb2fa4bb313a4a089c02b79f60ae563ea45102713a14b8f4a

See more details on using hashes here.

Provenance

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

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for lazy_log_formatter-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 188b679b99e8335d8f772b3988d581eeddabb235cb72b675f54cd14d548ed76d
MD5 64e2b977b8117c2769fff526260bcdb6
BLAKE2b-256 04413c86cd37dae48b1c0459d2b9c29e9bc763ba266271882fd8d170d24ca886

See more details on using hashes here.

Provenance

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

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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