Skip to main content

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

Metadata

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)

Source distribution for philiprehberger-log-focus 0.2.0
File Size Uploaded Provenance Actions
philiprehberger_log_focus-0.2.0.tar.gz 180.6 kB Without provenance Details for philiprehberger_log_focus-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for philiprehberger-log-focus 0.2.0
File Interpreter ABI Platform Actions
philiprehberger_log_focus-0.2.0-py3-none-any.whl Python 3 none any Details for philiprehberger_log_focus-0.2.0-py3-none-any.whl

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

Security for philiprehberger-log-focus 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page