pythonbeginner
Structured Logging for Data Pipelines
Use Loguru to emit structured JSON logs with contextual fields from ETL pipeline stages.
pythonPress ⌘/Ctrl + Shift + C to copy
from loguru import logger
import sys
logger.remove()
logger.add(sys.stdout, format='{message}', serialize=True)
def extract(source: str) -> list[dict]:
logger.info('Extract started', source=source)
records = [{'id': 1, 'val': 42}]
logger.info('Extract complete', records=len(records), source=source)
return records
extract('s3://my-bucket/events.json')Use Cases
- pipeline observability
- structured logging
- centralized log ingestion
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
typescriptbeginner
Structured JSON Logger
Build a structured logger with log levels, context, child loggers, and JSON output for Node.js services.
Best for: Application logging for production
#nodejs#logging
typescriptbeginner
Structured Request Logger Middleware
Express middleware that logs request/response details as structured JSON with timing information.
Best for: API monitoring
#express#logging
pythonintermediate
Structured Logging with structlog
Configure structlog for JSON-formatted structured logging with request context, timestamps, and log levels.
Best for: Application logging
#logging#structlog
javabeginner
Java Logging with SLF4J and Logback
Configure structured logging with SLF4J: log levels, MDC context, JSON format, and best practices.
Best for: Application logging with contextual information
#java#logging