Structured log filtering and highlighting for terminals
Project description
philiprehberger-log-focus
Structured log filtering and highlighting for terminals.
Installation
pip install philiprehberger-log-focus
Usage
Quick Setup
from philiprehberger_log_focus import focus
logger = focus("myapp")
logger.info("Server started")
logger.warning("High memory usage")
logger.error("Connection failed")
Custom Handler
import logging
from philiprehberger_log_focus import FocusHandler
handler = FocusHandler(
repeat_threshold=5, # Suppress after 5 identical messages
slow_threshold_ms=100, # Highlight slow operations
)
logger = logging.getLogger("myapp")
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
Slow Operation Highlighting
logger.info("Query completed", extra={"duration_ms": 250})
# Automatically highlighted if above slow_threshold_ms
Features
- Color-coded output by log level (DEBUG=gray, INFO=default, WARNING=yellow, ERROR=red, CRITICAL=bold red)
- Repeat suppression — collapses repeated identical messages
- Slow operation highlighting via
extra["duration_ms"]
API
| Function / Class | Description |
|---|---|
focus(name, level="WARNING") |
Quick setup, returns a configured logger |
FocusHandler(level, repeat_threshold, slow_key, slow_threshold_ms, stream) |
Custom logging handler with color and repeat suppression |
Colors |
ANSI escape constants — RESET, BOLD, DIM, RED, YELLOW, GRAY |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
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 philiprehberger_log_focus-0.1.9.tar.gz.
File metadata
- Download URL: philiprehberger_log_focus-0.1.9.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b9dabe1c7f8d3e7e7dc1f7f69ee75cc718ba67bb17b30b9195473a92ba18c69
|
|
| MD5 |
bf5a0c671ae27f791eb81c9c259a6f76
|
|
| BLAKE2b-256 |
745c87efce6300ce1ce2a430056ab78553290a929adb57eae02e6d9e7f5699fb
|
File details
Details for the file philiprehberger_log_focus-0.1.9-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_log_focus-0.1.9-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e046f353fbd36ceb9de8a7522b99d64ef988a049d79604432477d2f37382b37
|
|
| MD5 |
ca403cfcc0c2c871fc9c9650f2349506
|
|
| BLAKE2b-256 |
02d90037453725556a25e8c5c5a33a1628183811c66522462f00d23c8e4b315e
|