Skip to main content

Structured log filtering and highlighting for terminals

Project description

philiprehberger-log-focus

Tests PyPI version License

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=cyan, INFO=green, WARNING=yellow, ERROR=red, CRITICAL=magenta)
  • Repeat suppression — collapses repeated identical messages
  • Slow operation highlighting via extra["duration_ms"]

API

  • focus(name, level=DEBUG, repeat_threshold=10, slow_threshold_ms=100) — Quick setup, returns a configured logger
  • FocusHandler(repeat_threshold, slow_threshold_ms) — Custom logging handler

Development

pip install -e .
python -m pytest tests/ -v

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philiprehberger_log_focus-0.1.6.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_log_focus-0.1.6-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_log_focus-0.1.6.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_log_focus-0.1.6.tar.gz
Algorithm Hash digest
SHA256 c37d59a74296078bcca3156c237b016b661cd5f45ff00f443fd3c86a40339010
MD5 b8d5c0a6b65062d737d01bcf92865f04
BLAKE2b-256 718de98dae6a5ffd43b79990564a380967516b9eb973e520cd9727e98bd8cd31

See more details on using hashes here.

File details

Details for the file philiprehberger_log_focus-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_log_focus-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 49730321cd21cda2b9adac6b0694d5b6cd60a7ec9bade60ed52bacc727db9c4a
MD5 24ec446c964366f9056315bf1cbae8d1
BLAKE2b-256 632fffef90ed526497f25550849eedf32f33ac041fe2fe99d2a458cfb69bdc50

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page