Skip to main content

A colored logger with context injection support for Python applications.

Project description

Colored Context Logger

A generic, easy-to-use logging library supporting:

  • Colored console output (via coloredlogs).
  • Context injection: Add global context (e.g., session_id, config_name) to all log records automatically.
  • File logging: Easy attachment of file handlers.
  • Function tracing: @log_calls decorator to log function entry, exit, arguments, and execution time.

Installation

pip install colored-context-logger

Usage

1. Basic Setup & Context

from vibe_logger import setup_logger, GlobalLogContext, log_calls

# Setup Logger
logger = setup_logger(name="my_app", level="DEBUG")

# Set Global Context (will appear in all logs)
GlobalLogContext.update({"user": "alice", "request_id": "12345"})

logger.info("Processing request") 
# Output: 2025-01-01 12:00:00 INFO my_app ... user=alice request_id=12345 Processing request

2. File Logging

You can easily attach file handlers to your logger.

from vibe_logger import attach_file_handler

# Method A: Auto-generated filename based on context
# If 'session' is in GlobalLogContext, it uses that for the filename.
GlobalLogContext.update({"session": "main_process"})
log_path = attach_file_handler(logger_name="my_app", log_dir="logs")
print(f"Logging to: {log_path}") 
# Example: logs/main_process_20250101.log

# Method B: Specific filename
attach_file_handler(
    logger_name="my_app",
    log_dir="logs",
    filename="error.log",
    level="ERROR" # Only log errors to this file
)

3. Function Decorator

@log_calls()
def calculate(x, y):
    return x + y

calculate(1, 2)
# Output:
# ➡️ calculate Start (1, 2)
# ⬅️ calculate End 0.0001s Ret: int

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

vibe_colored_logger-0.1.5.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

vibe_colored_logger-0.1.5-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file vibe_colored_logger-0.1.5.tar.gz.

File metadata

  • Download URL: vibe_colored_logger-0.1.5.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vibe_colored_logger-0.1.5.tar.gz
Algorithm Hash digest
SHA256 85a762730a1490387fc3d2784a068eb2de2878cc3f844477677b7d9e02fed229
MD5 10c82f40401a495c9d88cefcb8e753c2
BLAKE2b-256 10fb864567b7b2848cbd994431fb87b4cc6f7151c6a4ca80f46ce35dd951588e

See more details on using hashes here.

Provenance

The following attestation bundles were made for vibe_colored_logger-0.1.5.tar.gz:

Publisher: pypi-vibe-colored-logger.yaml on jasoft/pythonlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vibe_colored_logger-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for vibe_colored_logger-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a472999c6d320ec1c5d4159603e31d0e9b1122d932204e7d1f933b683e5e34da
MD5 aef1363b2be660a5f02635510a903289
BLAKE2b-256 516c9c2ef2f7d16f958d65228279ade259bbfbb11c7ec069036021aa8af52683

See more details on using hashes here.

Provenance

The following attestation bundles were made for vibe_colored_logger-0.1.5-py3-none-any.whl:

Publisher: pypi-vibe-colored-logger.yaml on jasoft/pythonlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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