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:
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51328f5bcba12823ab8b38deb6afc57aed48a2d578bca671ebff247d3dffed36
|
|
| MD5 |
fcd1ea6a4b45645fd2b37194d629757c
|
|
| BLAKE2b-256 |
af43c59b48e1f9dbe09933358fc6983dbdde33f73dcd75b4be5e98a261671b97
|
Provenance
The following attestation bundles were made for lazy_log_formatter-0.5.1.tar.gz:
Publisher:
release.yaml on dmar1n/lazy-log-formatter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lazy_log_formatter-0.5.1.tar.gz -
Subject digest:
51328f5bcba12823ab8b38deb6afc57aed48a2d578bca671ebff247d3dffed36 - Sigstore transparency entry: 254855709
- Sigstore integration time:
-
Permalink:
dmar1n/lazy-log-formatter@7a2bcbdad8da4c85aca378275344db485668dfb0 -
Branch / Tag:
refs/tags/0.5.1 - Owner: https://github.com/dmar1n
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@7a2bcbdad8da4c85aca378275344db485668dfb0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lazy_log_formatter-0.5.1-py3-none-any.whl.
File metadata
- Download URL: lazy_log_formatter-0.5.1-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c79ac78f7993983135bc203a725a522b5393bdea8e86e6b9db5ccfddd3129edd
|
|
| MD5 |
925a986c78ba1a0878489c5571dbaad9
|
|
| BLAKE2b-256 |
888cf1fd1d8f95a5f014c7e9353d996bb3c92d72dfd30d823e86abfd0b772518
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lazy_log_formatter-0.5.1-py3-none-any.whl -
Subject digest:
c79ac78f7993983135bc203a725a522b5393bdea8e86e6b9db5ccfddd3129edd - Sigstore transparency entry: 254855727
- Sigstore integration time:
-
Permalink:
dmar1n/lazy-log-formatter@7a2bcbdad8da4c85aca378275344db485668dfb0 -
Branch / Tag:
refs/tags/0.5.1 - Owner: https://github.com/dmar1n
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@7a2bcbdad8da4c85aca378275344db485668dfb0 -
Trigger Event:
push
-
Statement type: