Cobli Logging Formatter
A structured JSON logging formatter with Datadog integration for Python applications.
Features
- Structured JSON Logging: Outputs logs in a consistent JSON format
- Datadog Integration: Automatically includes trace and span IDs from Datadog APM
- Timezone Aware: Timestamps in UTC with ISO 8601 format
- Custom Fields Support: Automatically captures and includes custom log fields
- Thread Information: Includes thread names for multi-threaded applications
- Exception Handling: Captures and formats stack traces
- Environment Configuration: Uses environment variables for service metadata
Installation
Using uv (recommended)
uv add cobli-logging-formatter
Using pip
pip install cobli-logging-formatter
Quick Start
Option 1: Use the preconfigured logger
from cobli_logging import get_logger
logger = get_logger()
logger.info("Hello, world!")
logger.error("Something went wrong", extra={"user_id": 123, "action": "login"})
Option 2: Use just the formatter
import logging
from cobli_logging import JsonFormatter
logger = logging.getLogger("my-service")
handler = logging.StreamHandler()
handler.setFormatter(JsonFormatter())
logger.addHandler(handler)
logger.setLevel(logging.INFO)
logger.info("Hello, world!")
Option 3: Use the configuration helper
from cobli_logging import configure_logging
# Configure with default settings
configure_logging()
# Or with custom settings
configure_logging(
service_name="my-custom-service",
log_level="DEBUG",
propagate=True
)
import logging
logger = logging.getLogger("my-custom-service")
logger.info("Configured logger ready!")
Configuration
The formatter uses the following environment variables:
DD_SERVICE: Service name for Datadog (optional)DD_VERSION: Service version for Datadog (optional)LOG_LEVEL: Logging level (default: "INFO")
Output Format
{
"timestamp": "2025-06-05T10:30:00Z",
"level": "INFO",
"message": "User logged in successfully",
"thread_name": "WorkerThread-1",
"dd": {
"trace_id": "1234567890123456789",
"span_id": "987654321",
"service": "user-service",
"version": "1.2.3"
},
"custom": {
"user_id": 123,
"action": "login",
"ip_address": "192.168.1.1"
},
"stack_trace": "Traceback (most recent call last):\n..."
}
Development
Quick start with Makefile
This project uses a comprehensive Makefile for all development tasks:
# Complete development setup
make dev-setup
# Run all quality checks (format, lint, test)
make check
# Run tests with coverage
make test-cov
# Build the package
make build
# Run examples
make examples
# See all available commands
make help
License
MIT License
Metadata
Release files for cobli-logging-formatter 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cobli_logging_formatter-1.0.1.tar.gz | 86.7 kB | Without provenance | Details for cobli_logging_formatter-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cobli_logging_formatter-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for cobli_logging_formatter-1.0.1-py3-none-any.whl |
Total release size: 93.8 kB
Release files / cobli_logging_formatter-1.0.1.tar.gz
| Download URL | cobli_logging_formatter-1.0.1.tar.gz |
|---|---|
| Size | 86.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
092d1578c68e6665c397190efaddca680fd74028b65c218d51614f69a1024e12
|
|
BLAKE2b-256 checksum How to use checksums |
fcd65a5c74ef6c22b39ec62f3c7edbbaa2204ce9e0044e239f1c201b5c6a685b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / cobli_logging_formatter-1.0.1-py3-none-any.whl
| Download URL | cobli_logging_formatter-1.0.1-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7928bf173c0f1ca98a725bf33d2962e37e043e9138ba3f57951bcad65f68f414
|
|
BLAKE2b-256 checksum How to use checksums |
af1b1d2a8962d52b34f805e4969fab9eca431eb3cfe2428cea312d07f34f407b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Security for cobli-logging-formatter 1.0.1
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.