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:
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.2
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
logging
module. Other logging libraries might not work as expected, such asloguru
. - Multi-line f-strings in the editor are not supported yet (they are simply ignored).
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
Built Distribution
File details
Details for the file lazy_log_formatter-0.4.2.tar.gz
.
File metadata
- Download URL: lazy_log_formatter-0.4.2.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cde1791b3543ea90aa47d2fe3e997b239880472eae8fd06fdb561af76a4488c8 |
|
MD5 | 0385f0342802c95c448a662d2e5780e1 |
|
BLAKE2b-256 | e06d3f1f420cf5f0d587b601f17fcfed714b823463c97909be87fc01c4fcd784 |
Provenance
The following attestation bundles were made for lazy_log_formatter-0.4.2.tar.gz
:
Publisher:
release.yaml
on dmar1n/lazy-log-formatter
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
lazy_log_formatter-0.4.2.tar.gz
- Subject digest:
cde1791b3543ea90aa47d2fe3e997b239880472eae8fd06fdb561af76a4488c8
- Sigstore transparency entry: 145937656
- Sigstore integration time:
- Predicate type:
File details
Details for the file lazy_log_formatter-0.4.2-py3-none-any.whl
.
File metadata
- Download URL: lazy_log_formatter-0.4.2-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b3ed23784ef8ad2a405231a66e735d6c051b34a46341a85e4eb1193c653f037 |
|
MD5 | cf0a6d93e10a1d4e683bdcafc9cb4d87 |
|
BLAKE2b-256 | 1de38477781b0c4506502bb990e9d7383d7b975823e0c2fc7f894907a2d9c402 |
Provenance
The following attestation bundles were made for lazy_log_formatter-0.4.2-py3-none-any.whl
:
Publisher:
release.yaml
on dmar1n/lazy-log-formatter
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
lazy_log_formatter-0.4.2-py3-none-any.whl
- Subject digest:
7b3ed23784ef8ad2a405231a66e735d6c051b34a46341a85e4eb1193c653f037
- Sigstore transparency entry: 145937658
- Sigstore integration time:
- Predicate type: