Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

ds-common-logger-py-lib

A Python logging library from the ds-common library collection, providing structured logging with support for extra fields, class-based loggers, and flexible configuration.

Installation

Install the package using pip:

pip install ds-common-logger-py-lib

Or using uv (recommended):

uv pip install ds-common-logger-py-lib

Features

  • Structured Logging: Extra fields included in log output
  • Logger Helper: Logger.configure() and Logger.get_logger() for consistent setup
  • Application Configuration: Prefix, format, handlers, and log levels from one place
  • Flexible Output: Update formats and prefixes at runtime
  • Custom Formatter: Extra fields are JSON-encoded when possible
  • Standard Library Compatible: Built on Python's logging module

Quick Start

Basic Usage

from ds_common_logger_py_lib import Logger

# Initialize logger configuration
Logger.configure()

# Get a logger instance
logger = Logger.get_logger(__name__)

# Log with extra fields
logger.info("Processing data", extra={"user_id": 123, "action": "process"})

Application Configuration

from ds_common_logger_py_lib import Logger
import logging

# Configure at application startup
Logger.configure(
    prefix="MyApp",
    format_string="[%(asctime)s][{prefix}][%(name)s][%(levelname)s]: %(message)s",
    level=logging.INFO
)

logger = Logger.get_logger(__name__)
logger.info("Application started")

# Update prefix at runtime
Logger.set_prefix("MyApp-session123")
logger.info("Session initialized")

Usage Examples

Setting Log Levels

from ds_common_logger_py_lib import Logger
import logging

Logger.configure(
    level=logging.DEBUG,
    logger_levels={
        "myapp.verbose": logging.DEBUG,
        "myapp.quiet": logging.WARNING,
    },
)

verbose_logger = Logger.get_logger("myapp.verbose")
quiet_logger = Logger.get_logger("myapp.quiet")

verbose_logger.debug("Debug message is visible")
quiet_logger.info("Info message is hidden")
quiet_logger.warning("Warning message is visible")

Multiple Classes with Isolated Loggers

from ds_common_logger_py_lib import Logger

class UserService:
    def create_user(self, username: str):
        logger = Logger.get_logger("services.user")
        logger.info("Creating user", extra={"username": username})

class OrderService:
    def create_order(self, user_id: int):
        logger = Logger.get_logger("services.order")
        logger.info("Creating order", extra={"user_id": user_id})

# Each class has its own logger with distinct names
user_service = UserService()
order_service = OrderService()

Requirements

  • Python 3.10 or higher

Documentation

Full documentation is available at:

Development

To contribute or set up a development environment:

# Clone the repository
git clone https://github.com/grasp-labs/ds-common-logger-py-lib.git
cd ds-common-logger-py-lib

# Install development dependencies
uv sync --all-extras --dev

# Run tests
make test

See the README for more information.

License

This package is licensed under the Apache License 2.0. See the LICENSE-APACHE file for details.

Support

Metadata

Release files for ds-common-logger-py-lib 0.1.0a6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ds-common-logger-py-lib 0.1.0a6
File Size Uploaded
ds_common_logger_py_lib-0.1.0a6.tar.gz 22.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ds-common-logger-py-lib 0.1.0a6
File Interpreter ABI Platform
ds_common_logger_py_lib-0.1.0a6-py3-none-any.whl Python 3 none any Details

Total release size: 36.7 kB

Release files / ds_common_logger_py_lib-0.1.0a6.tar.gz

Download URL ds_common_logger_py_lib-0.1.0a6.tar.gz
Size 22.0 kB
Tags Source
SHA-256 checksum
How to use checksums
47897a05f8ad6b0706d0a3ee32fc74b9ac5ae30460af658b8d34effabaa03f89
BLAKE2b-256 checksum
How to use checksums
5b79ca4d8837a0c2ff0052598fec40d6e178efb0e97e7edceb1dd58f1e2ed996
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / ds_common_logger_py_lib-0.1.0a6-py3-none-any.whl

Download URL ds_common_logger_py_lib-0.1.0a6-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72c16dd6877dc17d4595282ad65253cde7888d0b6884a0ff5a0f0e7b0f984b2b
BLAKE2b-256 checksum
How to use checksums
bb37f75f4c7fbd9a1d100b4c0f072af543934444a4d3aca0d4a9deed945c6c09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page