pythonbeginner

Structured Logging for Data Pipelines

Use Loguru to emit structured JSON logs with contextual fields from ETL pipeline stages.

python
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.