Skip to main content

Structured log filtering and highlighting for terminals

Project description

philiprehberger-log-focus

Tests PyPI version Last updated

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:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

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.2.0.tar.gz (180.6 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.2.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_log_focus-0.2.0.tar.gz
Algorithm Hash digest
SHA256 61c38dc53c7eafdf11fa51a5978b6e6ef120d0d33650e3bfaf6783ea18576a95
MD5 5d9a3813ba844d27248988f367f760ab
BLAKE2b-256 7196ff4395865232c28e9fd3afdea7c049323eb91083a39d04c2d085e55a5fc0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_log_focus-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad046850550f62d93a72e4452a587c08097072b49df4f59e11dbb9ccd75ef9bb
MD5 05b37f840515e5dc13aa6abf1f1a584f
BLAKE2b-256 f04a13d2c8ed0229af2818a00dd80b3e057efb1180b6717b7f169ca33434bdaf

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