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

Uploaded Python 3

File details

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

File metadata

  • Download URL: vibe_colored_logger-0.1.6.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.6.tar.gz
Algorithm Hash digest
SHA256 99bb2ecaa10f8e108f4215b5f828ecb6d4aaf636ca4f2a325a3652e37d8a750b
MD5 65a6b23a15c0a28879aabb7d65d53295
BLAKE2b-256 df7be6f90336598a6824d25239c1175326c8c188082c77d77876f19cf45eb20a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for vibe_colored_logger-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 7f1b48c87fa21143c1ac275e9d2626971e47430de0e44a3927313844613460ac
MD5 a8e490c2c213cd01b63235cc55de7712
BLAKE2b-256 1c6b68013d8e973dd7015a8f50307710294c78e08e9410e6370785aa233f38e4

See more details on using hashes here.

Provenance

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