Skip to main content

Enhanced Python logger with colorized output, TRACE/PROGRESS levels, UDP monitoring, file logging, and external config support via Loguru backend.

Project description

tracecolor

Enhanced Python logger with colorized output, TRACE/PROGRESS levels, UDP monitoring, and file logging. Powered by Loguru backend for superior performance and features.

Features

Core Features

  • Custom TRACE logging level (lower than DEBUG)
  • Custom PROGRESS logging level (between DEBUG and INFO)
  • Colorized output for different log levels
  • Rate-limiting for PROGRESS messages (once per second per call site)
  • Simple and clean API

Enhanced Features

  • Pure Loguru Backend: Superior performance and features
  • UDP Remote Monitoring: Real-time log streaming with tracecolor-monitor command
  • File Logging: Automatic rotation, compression, and retention
  • Automatic Configuration: Auto-detects .tracecolor, tracecolor.toml, tracecolor.yml, tracecolor.json
  • Multi-format Support: TOML/YAML/JSON configuration with automatic format detection
  • Multiple Destinations: Simultaneous logging to console, file, and UDP
  • Automatic Dependencies: Loguru installed automatically with pip install
  • Console Script: tracecolor-monitor available globally after installation
  • Enterprise Ready: Thread-safe, async support, production-grade

Installation

pip install tracecolor

This automatically installs:

  • loguru - Advanced logging backend
  • colorlog - Colorized console output

Optional Dependencies

# For YAML configuration support
pip install tracecolor[yaml]

# For development
pip install tracecolor[dev]

Usage

Basic Usage

from tracecolor import tracecolor

# Create a logger
logger = tracecolor(__name__)

# Log at different levels
logger.trace("Detailed tracing information")
logger.debug("Debugging information")
logger.progress("Progress update information (rate-limited)")
logger.info("General information")
logger.warning("Warning message")
logger.error("Error message")
logger.critical("Critical error")

Enhanced Usage (v0.6.0 Features)

from tracecolor import tracecolor

# Standard usage now automatically uses Loguru backend if available
logger = tracecolor(__name__)  # Now powered by Loguru!
logger.info("Better performance, same API")

# Enhanced features explicitly enabled
logger = tracecolor(
    name=__name__,
    enable_console=True,      # Console output (same as original)
    enable_udp=True,          # UDP remote monitoring
    enable_file=True,         # File logging with rotation
    log_dir="./logs",         # Log directory
    udp_host="127.0.0.1",     # UDP monitoring host
    udp_port=9999             # UDP monitoring port
)

# Same API as original tracecolor
logger.info("This message goes to console, file, AND UDP socket")
logger.progress("Progress messages still rate-limited, now with enterprise backend")

# Alternative: convenience function (same result)
from tracecolor import create_enhanced_logger
logger = create_enhanced_logger(__name__, enable_udp=True, enable_file=True, log_dir="logs")

# Monitor logs in real-time (separate terminal)
# tracecolor-monitor
# or: python -m tracecolor.monitor

External Configuration

Automatic Config Detection

Tracecolor automatically looks for standard config files in the current directory:

  1. .tracecolor (auto-detects format: TOML/YAML/JSON - first priority)
  2. tracecolor.toml (TOML config)
  3. tracecolor.yml (YAML config)
  4. tracecolor.yaml (YAML alternate)
  5. tracecolor.json (JSON config)
# Just create .tracecolor in your project directory (any format)
from tracecolor import tracecolor
logger = tracecolor(__name__)  # Automatically finds and parses .tracecolor

The .tracecolor file automatically detects its format, so you can use TOML, YAML, or JSON - whatever you prefer!

Manual Config File

# Create custom_config.yml
logger = tracecolor(__name__, config_file="custom_config.yml")

Config File Formats

.tracecolor supports all formats - auto-detected!

TOML format:

# TraceColor Configuration
[udp]
enabled = true
host = "127.0.0.1"
port = 9999

[console]
enabled = true
level = "TRACE"

[file]
enabled = false
dir = "./logs"

YAML:

log_level: TRACE
use_udp: true
udp_host: 127.0.0.1
udp_port: 9999
enable_console: true
enable_file: true
log_dir: "./logs"

JSON:

{
    "log_level": "TRACE",
    "use_udp": true,
    "udp_host": "127.0.0.1", 
    "udp_port": 9999,
    "enable_console": true,
    "enable_file": true,
    "log_dir": "./logs"
}

UDP Remote Monitoring

Monitor logs in real-time from any application using enhanced features:

# Terminal 1: Run your application with UDP logging
python your_app.py

# Terminal 2: Monitor logs in real-time
python -m tracecolor.monitor

# Or specify host/port
python -m tracecolor.monitor --host 0.0.0.0 --port 8888

# Legacy format also supported
python tracecolor/monitor.py listen 192.168.1.100 9999

The monitor displays formatted output with timestamps, log levels, and messages in real-time.

Migration Guide

From v0.5.0 to v0.6.0

Step 1: Update package (existing code continues to work)

pip install --upgrade tracecolor

Step 2: Install enhanced dependencies (optional)

pip install tracecolor[enhanced]

Step 3: Optionally enable enhanced features where needed

# Before (still works, now with Loguru backend!)
from tracecolor import tracecolor
logger = tracecolor(__name__)  # Automatically uses Loguru if available

# Enhanced features when needed
logger = tracecolor(__name__, enable_udp=True, enable_file=True, log_dir="logs")

Step 4: Add external configuration as projects mature

# Automatic config detection (looks for tracecolor.yml, tracecolor.yaml, tracecolor.json)
logger = tracecolor(__name__)  # Auto-detects config files

# Or specify custom config file
logger = tracecolor(__name__, config_file="custom_config.yml")

Color Scheme

  • TRACE: Gray (bold black)
  • DEBUG: Cyan
  • PROGRESS: Blue
  • INFO: Green
  • WARNING: Yellow
  • ERROR: Red
  • CRITICAL: Bold Red

Examples

See the examples/ directory for comprehensive usage examples:

  • basic_usage.py - Original v0.5.0 functionality
  • enhanced_features.py - New v0.6.0 features and migration guide

License

MIT

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

tracecolor-0.7.15.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

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

tracecolor-0.7.15-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file tracecolor-0.7.15.tar.gz.

File metadata

  • Download URL: tracecolor-0.7.15.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tracecolor-0.7.15.tar.gz
Algorithm Hash digest
SHA256 87706177fd94fbc6aa8ce22a5ab96596e0208afdd9de228e1d15a64ec2d61dea
MD5 bbd6a9fec17c87b7b4c6c26a19de3df1
BLAKE2b-256 9c7e87a4ce00bc8756893a827de62d91b4d491508adbbf833f5481387ca56043

See more details on using hashes here.

File details

Details for the file tracecolor-0.7.15-py3-none-any.whl.

File metadata

  • Download URL: tracecolor-0.7.15-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tracecolor-0.7.15-py3-none-any.whl
Algorithm Hash digest
SHA256 2e54b58566ff5d5555daee03b2134d5e933157ff0a1993803e6e4fcb1c13fd7a
MD5 615e01a0510375255c9262a447bc69e6
BLAKE2b-256 c16418cd94a835c88c1fd527f3da9fda2b47e171ff07c768008bfdaf8824b322

See more details on using hashes here.

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