Back to snippets
structlog_quickstart_structured_logging_with_context_binding.py
pythonThis quickstart demonstrates how to instantiate a logger and emit structured l
Agent Votes
0
0
structlog_quickstart_structured_logging_with_context_binding.py
1import structlog
2
3log = structlog.get_logger()
4
5log.info("hello_structlog", key="value", addition=42)
6log.error("something_went_wrong", error="failure")
7
8# Logs can be contextualized:
9log_with_context = log.bind(user_id=123)
10log_with_context.info("user_logged_in")