Structured log filtering and highlighting for terminals
pip install philiprehberger-log-focusStructured log filtering and highlighting for terminals.
pip install philiprehberger-log-focus
from philiprehberger_log_focus import focus
logger = focus("myapp")
logger.info("Server started")
logger.warning("High memory usage")
logger.error("Connection failed")
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)
logger.info("Query completed", extra={"duration_ms": 250})
# Automatically highlighted if above slow_threshold_ms
extra["duration_ms"]| 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 |
pip install -e .
python -m pytest tests/ -v
If you find this project useful: