🧩 logguard
logguard is a lightweight Python utility that automatically redacts sensitive data from logs protecting tokens, passwords, emails, and other secrets from accidental exposure.
It combines keyword-based filtering and smart heuristic detection for robust, production-grade log sanitization.
🚀 Features
- 🔐 Keyword-based redaction using an extensive list (
sensitive_keys.txt) - 🧠 Heuristic detection for:
- Emails
- Tokens & secrets
- UUIDs
- JWTs
- Credit card numbers
- AWS keys and access tokens
- 🪄
RedactingFormatterfor automatic log sanitization - 🧩
@filterdecorator to patchloggingdynamically - ⚡ Lightweight and dependency-free
⚙️ Installation
pip install logguard
or use directly from your local source:
pip install .
💡 Quick Start
import logging
from logguard import RedactingFormatter, filter
handler = logging.StreamHandler()
handler.setFormatter(RedactingFormatter("%(levelname)s: %(message)s"))
logger = logging.getLogger("demo")
logger.addHandler(handler)
logger.setLevel(logging.INFO)
logger.info("email=user@example.com")
logger.info("User signed in: email=user@example.com, password=secret123, api_key=abcd-1234-efgh, token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9")
logger.info("Payment info: card=4111-1111-1111-1111, uuid=550e8400-e29b-41d4-a716-446655440000, aws=AKIA1234567890ABCDEF")
@filter
def do_work():
logging.info("This contains a secret: client_secret=verysecret")
do_work()
✅ Output:
INFO: email=[REDACTED]
INFO: User signed in: email=[REDACTED], password=[REDACTED], api_key=[REDACTED], token=[REDACTED]
INFO: Payment info: card=[REDACTED], uuid=[REDACTED], aws=[REDACTED]
🧠 How It Works
logguard uses a hybrid redaction model:
-
Keyword matching
Searches for field names likepassword,token,api_key,client_secretfromsensitive_keys.txt.password=12345 → password=[REDACTED] -
Heuristic detection
Even if a field name isn’t known, patterns like long random strings, emails, or UUIDs are automatically redacted.token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 → token=[REDACTED]
This ensures no sensitive value leaks into log files — even when variable names differ.
🧰 Advanced Usage
Custom Sensitive Keys
You can extend the default sensitive_keys.txt file with your own entries:
custom_secret
internal_token
Reload your package or re-import logguard to apply them.
Direct Redaction Function
You can also manually call the sanitizer:
from logguard import redact
text = "email=user@example.com, password=secret123"
print(redact(text))
# → email=[REDACTED], password=[REDACTED]
🧩 Example Patterns (v2)
| Type | Example | Redacted |
|---|---|---|
user@example.com |
[REDACTED] |
|
| Token | abcd1234efgh5678ijkl9012 |
[REDACTED] |
| UUID | 550e8400-e29b-41d4-a716-446655440000 |
[REDACTED] |
| Credit Card | 4111-1111-1111-1111 |
[REDACTED] |
| JWT | eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 |
[REDACTED] |
| AWS Key | AKIA1234567890ABCDEF |
[REDACTED] |
⚠️ Notes
- Avoid excessive redaction in structured logs
- Regex-based redaction may slightly impact performance on large-scale systems
- Future versions will add:
- JSON-aware redaction
- Async logging support
- Developer tagging (
@sensitivedecorator)
🧡 License
MIT License © 2025 — Developed for safe and responsible logging.
Metadata
Release files for logguard 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| logguard-2.0.0.tar.gz | 5.4 kB | Without provenance | Details for logguard-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| logguard-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for logguard-2.0.0-py3-none-any.whl |
Total release size: 11.6 kB
Release files / logguard-2.0.0.tar.gz
| Download URL | logguard-2.0.0.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9dc46b27db0df63af16e98c6017b353e57b0775d982c265c9522c23ce8ef6ea1
|
|
BLAKE2b-256 checksum How to use checksums |
2442a2deb7f2984d1dd9dbc947b4193c0172adf99f4c728e5cb26dd020dff147
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Release files / logguard-2.0.0-py3-none-any.whl
| Download URL | logguard-2.0.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4bc04c9936fdc8b05d02a733ff85e667ca432a93874f9ae4b6f1be67d4fc83ab
|
|
BLAKE2b-256 checksum How to use checksums |
8d9b90b0ef739c57f857237d62804027dfbfbe400354bf83aa3d55394b55d6db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Security for logguard 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.