Skip to main content

A flexible logging library with support for cloud providers, multi-tenancy, and structured logging

Project description

DC Logger

Python 3.8+ License: MIT

A flexible, async-first structured logging library for Python with support for multiple handlers, cloud providers, distributed tracing, and multi-tenancy.

Features

  • Async-first design - Non-blocking logging for high-performance applications
  • Structured logging - JSON-based logs with entities, actions, and context
  • Multiple handlers - Console, file, and cloud output simultaneously
  • Cloud integrations - Datadog, AWS CloudWatch, GCP, Azure support
  • Distributed tracing - Built-in correlation with trace/span IDs
  • Decorator logging - Automatic function entry/exit logging with @log_call
  • Multi-tenant support - Tenant context for SaaS applications
  • Colored console output - ANSI colors for better visibility

Installation

pip install dc_logger

# With Datadog support
pip install dc_logger[datadog]

# With all extras
pip install dc_logger[all]

Quick Start

import asyncio
from dc_logger import DCLogger, ConsoleLogConfig, LogLevel

async def main():
    config = ConsoleLogConfig(level=LogLevel.INFO)
    logger = DCLogger(config, "my_app")
    
    await logger.info("Application started")
    await logger.warning("This is a warning")
    await logger.error("Something went wrong")
    
    await logger.close()

asyncio.run(main())

Using the Decorator

from dc_logger import log_call

@log_call(action_name="process", include_params=True)
async def process_data(data_id: str):
    # Automatically logs entry, exit, duration, and errors
    return {"status": "processed"}

Structured Logging with Context

from dc_logger import LogEntity

entity = LogEntity(type="dataset", id="ds_123", name="Sales Data")

await logger.info(
    "Dataset processed",
    entity=entity,
    action="process_dataset",
    duration_ms=1500,
    extra={"rows": 10000}
)

Multi-Handler Configuration

from dc_logger import create_console_file_config

config = create_console_file_config(
    file_path="logs/app.log",
    level=LogLevel.INFO,
    pretty_print=True
)
logger = DCLogger(config, "my_app")

Documentation

Document Description
USAGE.md Comprehensive usage guide
API_REFERENCE.md Complete API documentation
docs/getting-started.md Step-by-step introduction
docs/configuration.md Configuration options
docs/best-practices.md Recommended patterns
examples/ Working example scripts

For AI Agents

See .ai/context.md for a quick reference guide optimized for AI agents.

Key Components

Component Import Description
DCLogger from dc_logger import DCLogger Main logger class
ConsoleLogConfig from dc_logger import ConsoleLogConfig Console configuration
LogLevel from dc_logger import LogLevel Log levels (DEBUG, INFO, etc.)
LogEntity from dc_logger import LogEntity Entity context for logs
HTTPDetails from dc_logger import HTTPDetails HTTP request details
log_call from dc_logger import log_call Function logging decorator
get_logger from dc_logger import get_logger Get global logger
correlation_manager from dc_logger import correlation_manager Distributed tracing

Log Levels

LogLevel.DEBUG      # Detailed debugging information
LogLevel.INFO       # General informational messages
LogLevel.WARNING    # Warning messages for potential issues
LogLevel.ERROR      # Error messages for failures
LogLevel.CRITICAL   # Critical errors requiring immediate attention

Cloud Integrations

Datadog

from dc_logger import create_console_datadog_config

config = create_console_datadog_config(
    datadog_api_key="your-api-key",
    datadog_service="my-service",
    datadog_env="production"
)

Architecture

See documentation/architecture.md for design details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Jae Wilson (@jaewilson07)

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

dc_logger-1.2.0.tar.gz (50.7 kB view details)

Uploaded Source

Built Distribution

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

dc_logger-1.2.0-py3-none-any.whl (60.6 kB view details)

Uploaded Python 3

File details

Details for the file dc_logger-1.2.0.tar.gz.

File metadata

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

File hashes

Hashes for dc_logger-1.2.0.tar.gz
Algorithm Hash digest
SHA256 92e53efccf24988fc589823a21382b9ce22315609356819d7a783568b551a474
MD5 e2ff1aaa54a8139391cca109d8399811
BLAKE2b-256 94a0d118541880851fc8a618dee2227f18ec800591c574715ed57ea2fc417505

See more details on using hashes here.

File details

Details for the file dc_logger-1.2.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for dc_logger-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4364536de668f874981b2829da8af1c8759f5e166261f0f85c6beea3ec87317a
MD5 ce5de36cfbdeb58511e6e9d943975794
BLAKE2b-256 809ac9a48cdf4bbfd674c7077fd611c389025d72d7f610627db39d6b0442d64b

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