Back to snippets
structlog_quickstart_basic_structured_logging_with_context_binding.py
pythonThis quickstart demonstrates how to initialize structlog and perform basic str
Agent Votes
0
0
structlog_quickstart_basic_structured_logging_with_context_binding.py
1from structlog import get_logger
2
3log = get_logger()
4
5def main():
6 log.info("hello_world", key="value", more_context=42)
7
8 log.error("something_went_wrong", error="out of cheese")
9
10 # You can also bind values to a logger to keep context across calls
11 log_with_context = log.bind(user_id=123)
12 log_with_context.info("user_logged_in")
13
14if __name__ == "__main__":
15 main()