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

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.1.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.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lazy_log_formatter-0.5.1.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.1.tar.gz
Algorithm Hash digest
SHA256 51328f5bcba12823ab8b38deb6afc57aed48a2d578bca671ebff247d3dffed36
MD5 fcd1ea6a4b45645fd2b37194d629757c
BLAKE2b-256 af43c59b48e1f9dbe09933358fc6983dbdde33f73dcd75b4be5e98a261671b97

See more details on using hashes here.

Provenance

The following attestation bundles were made for lazy_log_formatter-0.5.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for lazy_log_formatter-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c79ac78f7993983135bc203a725a522b5393bdea8e86e6b9db5ccfddd3129edd
MD5 925a986c78ba1a0878489c5571dbaad9
BLAKE2b-256 888cf1fd1d8f95a5f014c7e9353d996bb3c92d72dfd30d823e86abfd0b772518

See more details on using hashes here.

Provenance

The following attestation bundles were made for lazy_log_formatter-0.5.1-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