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
coloredlogsfor 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_callsdecorator 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d12b7a4d96e2df50546888a268a6f98598c47dec059726cf56e9e8ced3e09206
|
|
| MD5 |
39afce55ed4f48ba22e145f7213ca6c3
|
|
| BLAKE2b-256 |
715255fd22fe729007240cc0325d824a904c06bf75ef732f96b1b56a61aa7549
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vibe_colored_logger-0.1.7.tar.gz -
Subject digest:
d12b7a4d96e2df50546888a268a6f98598c47dec059726cf56e9e8ced3e09206 - Sigstore transparency entry: 836076834
- Sigstore integration time:
-
Permalink:
jasoft/pythonlib@8214335ec782678d11bba943fb757a1bac3d51c1 -
Branch / Tag:
refs/tags/vibe-logger-v0.1.7 - Owner: https://github.com/jasoft
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-vibe-colored-logger.yaml@8214335ec782678d11bba943fb757a1bac3d51c1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file vibe_colored_logger-0.1.7-py3-none-any.whl.
File metadata
- Download URL: vibe_colored_logger-0.1.7-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bb47358ac45478f8dbd93cc8900915eef827c23fbb8ba41d23ddc0aeda5c5d0
|
|
| MD5 |
32049be3f10f0f61c64a51c841a7312b
|
|
| BLAKE2b-256 |
a5cc4d2a771f5186b82553f39b339f0989eafd70d77c8fd544c9cc17f63ffa81
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vibe_colored_logger-0.1.7-py3-none-any.whl -
Subject digest:
8bb47358ac45478f8dbd93cc8900915eef827c23fbb8ba41d23ddc0aeda5c5d0 - Sigstore transparency entry: 836076836
- Sigstore integration time:
-
Permalink:
jasoft/pythonlib@8214335ec782678d11bba943fb757a1bac3d51c1 -
Branch / Tag:
refs/tags/vibe-logger-v0.1.7 - Owner: https://github.com/jasoft
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-vibe-colored-logger.yaml@8214335ec782678d11bba943fb757a1bac3d51c1 -
Trigger Event:
push
-
Statement type: