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
Removing the handler
from philiprehberger_log_focus import unfocus
unfocus("my-logger")
# All FocusHandler instances are detached from the named logger.
# The logger's level is left unchanged.
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 |
unfocus(name=None) |
Remove all FocusHandler instances from the named logger and return it |
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, GREEN, YELLOW, CYAN, GRAY |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Release files for philiprehberger-log-focus 0.2.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 | |
|---|---|---|---|
| philiprehberger_log_focus-0.2.0.tar.gz | 180.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| philiprehberger_log_focus-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 186.0 kB
Release files / philiprehberger_log_focus-0.2.0.tar.gz
| Download URL | philiprehberger_log_focus-0.2.0.tar.gz |
|---|---|
| Size | 180.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
61c38dc53c7eafdf11fa51a5978b6e6ef120d0d33650e3bfaf6783ea18576a95
|
|
BLAKE2b-256 checksum How to use checksums |
7196ff4395865232c28e9fd3afdea7c049323eb91083a39d04c2d085e55a5fc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / philiprehberger_log_focus-0.2.0-py3-none-any.whl
| Download URL | philiprehberger_log_focus-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ad046850550f62d93a72e4452a587c08097072b49df4f59e11dbb9ccd75ef9bb
|
|
BLAKE2b-256 checksum How to use checksums |
f04a13d2c8ed0229af2818a00dd80b3e057efb1180b6717b7f169ca33434bdaf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|