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=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

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.7.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.7-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_log_focus-0.1.7.tar.gz
Algorithm Hash digest
SHA256 8a1c67ebdaa15140f2c2762d6a9daf20cd078397dc4713d9ff1bfa0e8f44f40d
MD5 668629a60a3d68a6ecff121d15a9a25e
BLAKE2b-256 2a0ab31af8a85429017f23bf151227c55f77f2eb48020cd576ef68cab2f36e2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_log_focus-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 fd89684324d4a82a3a10c17dad4652b7d2a053d78112290c0076cfd72d63b4e2
MD5 84311f03872221cbd90985556dee470d
BLAKE2b-256 cd09d8d5f2ff5343fb9e305cee540b515f4320952cf9a0e6d7455026bf720644

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