Skip to main content

Python Structlog Config

Structured logging configuration with optional OpenTelemetry and Sentry integration.

Extracted from: GridFlow backend/src/infrastructure/logging_config.py

Installation

# Basic installation
pip install python-structlog-config

# With OTel support
pip install python-structlog-config[otel]

# With Sentry support
pip install python-structlog-config[sentry]

# With all integrations
pip install python-structlog-config[all]

Features

  • Structured Logging: JSON or console output
  • OpenTelemetry: Optional OTel instrumentation
  • Sentry: Optional Sentry error tracking
  • Presets: Development, production, and testing configurations

Usage

Quick Start

from python_structlog_config import configure_for_development, get_logger

# Configure logging for development
configure_for_development("my-api")

# Get logger
logger = get_logger(__name__)
logger.info("Application started", version="1.0.0")

Production Setup

from python_structlog_config import configure_for_production

configure_for_production(
    "my-api",
    sentry_dsn="https://...@sentry.io/...",
    log_level="INFO"
)

Custom Configuration

from python_structlog_config import configure_structlog

configure_structlog(
    log_level="DEBUG",
    json_output=True,
    enable_otel=True,
    enable_sentry=True,
    sentry_dsn="https://...@sentry.io/...",
    service_name="my-api",
    environment="staging"
)

Testing Setup

from python_structlog_config import configure_for_testing

configure_for_testing("my-api")

Presets

Development

  • Log Level: DEBUG
  • Output: Console (human-readable)
  • OTel: Disabled
  • Sentry: Disabled

Production

  • Log Level: INFO
  • Output: JSON
  • OTel: Enabled
  • Sentry: Optional (if DSN provided)

Testing

  • Log Level: WARNING
  • Output: Console
  • OTel: Disabled
  • Sentry: Disabled

API Reference

configure_structlog(...)

Configure structlog with optional integrations.

Parameters:

  • log_level (str): Logging level (default: "INFO")
  • json_output (bool): Use JSON renderer (default: False)
  • enable_otel (bool): Enable OTel (default: False)
  • enable_sentry (bool): Enable Sentry (default: False)
  • sentry_dsn (Optional[str]): Sentry DSN
  • service_name (Optional[str]): Service name
  • environment (Optional[str]): Environment name

get_logger(name=None)

Get a structlog logger instance.

Parameters:

  • name (Optional[str]): Logger name

Returns:

  • Structlog logger instance

Presets

  • configure_for_development(service_name): Development preset
  • configure_for_production(service_name, sentry_dsn, log_level): Production preset
  • configure_for_testing(service_name): Testing preset

Integrations

OpenTelemetry

Requires: pip install python-structlog-config[otel]

configure_structlog(enable_otel=True, service_name="my-api")

Sentry

Requires: pip install python-structlog-config[sentry]

configure_structlog(
    enable_sentry=True,
    sentry_dsn="https://...@sentry.io/...",
    environment="production"
)

Dependencies

  • structlog>=23.0.0

Optional:

  • opentelemetry-instrumentation-logging>=0.40b0 (OTel)
  • sentry-sdk>=1.40.0 (Sentry)

License

MIT

Metadata

Release files for python-structlog-config 0.1.0

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

Source distribution (sdist)

Source distribution for python-structlog-config 0.1.0
File Size Uploaded Provenance Actions
python_structlog_config-0.1.0.tar.gz 4.9 kB Without provenance Details for python_structlog_config-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-structlog-config 0.1.0
File Interpreter ABI Platform Actions
python_structlog_config-0.1.0-py3-none-any.whl Python 3 none any Details for python_structlog_config-0.1.0-py3-none-any.whl

Total release size: 10.6 kB

Release files / python_structlog_config-0.1.0.tar.gz

Download URL python_structlog_config-0.1.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
056d07e59f9ea932a755c81129457d946ed7aafbcc4ff48506f17180650f865d
BLAKE2b-256 checksum
How to use checksums
10ac81dd63d4227d0c622968d0e1a827f9e3bff44e53ae3b3815291351d51261
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / python_structlog_config-0.1.0-py3-none-any.whl

Download URL python_structlog_config-0.1.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24cc834e18e604e91e8289e75aa7998fcf288ee95e93a75f24a4503b989e4e57
BLAKE2b-256 checksum
How to use checksums
8622807bee771932fb1bccd6d3cedf579347710169be70c49bdc3b7e38c01413
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Security for python-structlog-config 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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