pfly - Python LOggling Linter
Project description
A Python logging linter that enforces best practices
Why?
Production incidents are harder to debug when:
- Exception logs lack stack traces (
exc_info=True) - Hot loops spam logs, degrading performance
- Inconsistent logging causes time delay in parsing logs
- Complementary: Use with
structlog,loguru— not instead of them
Installation
uv pip install pfly
Usage
pfly path/to/code
pfly path/to/code --config=pfly.yml
Policies
| Code | Policy | Description |
|---|---|---|
| LY001 | exception_exc_info |
Enforces exc_info=True for logs in exception handlers to capture stack traces in a consistent format |
| LY002 | log_loop |
Prevents unconditional logging in hot loops (allows conditional logging) |
| LY003 | consistent_kv |
Ensures log variables follow key-value format for consistent parsing |
Configuration
Create a pfly.yml:
logger_names: [logger, logging, log]
exception_exc_info:
levels: [error]
severity: fail
log_loop:
levels: [info, debug]
severity: fail
Examples
LY001: Missing exc_info=True
# Fail
try:
connect_db()
except Exception:
logger.error("Connection failed") # No stack trace!
# Pass
try:
connect_db()
except Exception:
logger.error("Connection failed", exc_info=True)
LY002: Logging in hot loops
# Fail
for user in users:
logger.info(f"Processing {user}") # Logs every iteration
# Pass
for i, user in enumerate(users):
if i % 100 == 0:
logger.info(f"Progress: {i}/{len(users)}") # Conditional logging
LY003: Inconsistent key-value logging
# Fail
logger.info(f"User {user}") # Missing key
logger.info("User %s", user) # Placeholder without key
# Pass
logger.info(f"User user={user}") # Key-value pair
logger.info("User user=%s", user) # Key=placeholder format
License
Apache
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
pfly-0.1.1.tar.gz
(1.3 MB
view details)
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
pfly-0.1.1-py3-none-any.whl
(15.3 kB
view details)
File details
Details for the file pfly-0.1.1.tar.gz.
File metadata
- Download URL: pfly-0.1.1.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2eddccb61b9c16c6a5ebff2dc7a8106bac5c39497ca84cb42a5c6ba713aeb1c5
|
|
| MD5 |
8b996395866fc30bd525349a7a005cf6
|
|
| BLAKE2b-256 |
88affd15acf9607602e185bc07caed8c6cd2b097655175e5cf22ac24dbdc6035
|
File details
Details for the file pfly-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pfly-0.1.1-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
760369b1fb55d8c5089bc892fb9f772026742cdc627aeeb39b5e93d096ab9b84
|
|
| MD5 |
1d278fa24ec28ddb8cd123cb451d4368
|
|
| BLAKE2b-256 |
384551a9a3fd220ad84681b0184dfd6befc7331d8e329497dc0946a1c8d80fc6
|