ONS Dissemination JSON log formatter for Python Lambda functions.
Implements the ONS logging standards as a reusable package.
pip install dis-loggingOr with Poetry:
[tool.poetry.dependencies]
dis-logging = "^1.0.0"Call configure_logging() once in your handler file:
from dis_logging import configure_logging
configure_logging()That's it. All loggers in your code will output structured JSON. No arguments required — it reads configuration from environment variables.
- Configures the root logger with the ONS JSON format
- Every
logging.getLogger(__name__)in your code inherits the formatter - Third-party libraries (boto3, urllib3) are automatically covered
- If
APP_LOG_LEVELis set, your app code gets a separate log level while third-party libraries stay at the root level — so you canDEBUGyour code without drowning in boto noise
# my_module/handler.py
import logging
from dis_logging import configure_logging
configure_logging()
logger = logging.getLogger(__name__)
def lambda_handler(event, context):
logger.info("Processing event", extra={"event_id": event.get("id")})
return {"statusCode": 200}Output:
{"created_at": "2024-01-15T10:30:00", "namespace": "my_module.handler", "severity": 3, "event": "Processing event", "data": {"event_id": "abc123"}}| Environment variable | Description | Default |
|---|---|---|
LOG_LEVEL |
Root logger level (all loggers) | INFO |
APP_LOG_LEVEL |
Your app code's log level (auto-detected from caller package) | — |
| Level | Severity |
|---|---|
| CRITICAL | 0 |
| ERROR | 1 |
| WARNING | 2 |
| INFO | 3 |
| DEBUG | 4 |
make install # Install dependencies
make test # Run tests
make lint # Run linting
make format # Auto-format
make all # Run everythingReleases are automated. To create a new release:
- Bump the
versioninpyproject.tomlas part of your PR - Merge to
main - The release workflow automatically creates a GitHub Release and tag
Full contributing guidelines are covered here.