Skip to main content

A colored logger with context injection support for Python applications.

Project description

Colored Context Logger (vibe-colored-logger)

A generic, easy-to-use logging library designed for modern Python applications. It enhances standard logging with colored console output, automatic context injection, and simplified file handler management.

Installation

pip install vibe-colored-logger

Features

  • Colored Console Output: Integrated with coloredlogs for readable, severity-based coloring.
  • Global Context Injection: Automatically inject context (e.g., session_id, user_id, environment) into every log record. Great for tracking requests across functions.
  • Simplified File Logging: One-line command to attach file handlers, with support for dynamic filenames based on context.
  • Function Tracing: @log_calls decorator to automatically log function entry, exit, arguments, return values, and execution time.

Usage Guide

1. Basic Setup & Context

Initialize the logger and set global context variables that will appear in all log entries.

from vibe_logger import setup_logger, GlobalLogContext

# 1. Setup Logger (Standard Python logging wrapper)
logger = setup_logger(name="PaymentService", level="DEBUG")

# 2. Set Global Context
# These key-values will be appended to every log message automatically.
GlobalLogContext.update({
    "env": "production",
    "version": "v1.2.0",
    "request_id": "req_8848"
})

logger.info("Service initialized")
# Output: [INFO] ... env=production version=v1.2.0 request_id=req_8848 Service initialized

2. File Logging

Easily attach file handlers. You can specify a fixed filename or let the logger generate one based on the context (e.g., a specific session ID).

from vibe_logger import attach_file_handler

# Method A: Attach to a specific directory
# Filename will be auto-generated or based on 'session' context if present.
log_path = attach_file_handler(
    logger_name="PaymentService",
    log_dir="logs/payments",
    level="DEBUG"
)
print(f"Logging to: {log_path}")

# Method B: Specify exact filename
attach_file_handler(
    logger_name="PaymentService",
    log_dir="logs",
    filename="errors.log",
    level="ERROR" # Only log errors here
)

3. Function Tracing (@log_calls)

Use the @log_calls decorator to debug function execution without writing boilerplate print statements.

from vibe_logger import log_calls

@log_calls(level="DEBUG")
def process_payment(amount, currency):
    if amount <= 0:
        raise ValueError("Invalid amount")
    return f"Processed {amount} {currency}"

# Calling the function will log:
# ➡️ process_payment Start (100, 'USD')
# ⬅️ process_payment End 0.002s Ret: 'Processed 100 USD'

4. Integration with Existing Loggers

If you have an existing logging configuration, you can use GlobalLogContext to inject data into it, provided you format your logs to include the context fields. vibe-colored-logger handles the formatting automatically when using setup_logger.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: vibe_colored_logger-0.1.7.tar.gz
  • Upload date:
  • Size: 6.1 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.7.tar.gz
Algorithm Hash digest
SHA256 d12b7a4d96e2df50546888a268a6f98598c47dec059726cf56e9e8ced3e09206
MD5 39afce55ed4f48ba22e145f7213ca6c3
BLAKE2b-256 715255fd22fe729007240cc0325d824a904c06bf75ef732f96b1b56a61aa7549

See more details on using hashes here.

Provenance

The following attestation bundles were made for vibe_colored_logger-0.1.7.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.7-py3-none-any.whl.

File metadata

File hashes

Hashes for vibe_colored_logger-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8bb47358ac45478f8dbd93cc8900915eef827c23fbb8ba41d23ddc0aeda5c5d0
MD5 32049be3f10f0f61c64a51c841a7312b
BLAKE2b-256 a5cc4d2a771f5186b82553f39b339f0989eafd70d77c8fd544c9cc17f63ffa81

See more details on using hashes here.

Provenance

The following attestation bundles were made for vibe_colored_logger-0.1.7-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