Python Conference APAC 2024

Structlog in Practice
2024-10-27 , CLASS #3
Language: English

In the era of cloud computing, it is essential to have logs that are structured using JSON and include the context of where the logs came from. This talk will show how to use structlog with Django, Celery, and Sentry in a real web application development scenario.


Easy-to-use logging libraries are great because you can start using them quickly. However, in more complex systems, it's more important to have a library that can handle the complexity and consistently produce traceable logs, rather than just being easy to use.
In the cloud era, logs need to be in a structured JSON format so they can be handled by machines. Also, to improve traceability, the context information of each log should be included in the framework's log output. Such traceable logs can greatly reduce the effort needed for troubleshooting.
Structlog can be customized to meet these needs, but its high customization can be a barrier at first.
The planned agenda is as follows:
・Structured and contextual logging required in the cloud era for Python + Web (3 mins)
・Recommended logging library for the cloud era: structlog (5 mins)
・Setting up structured log output with structlog (5 mins)
・How to use context information output by structlog effectively (3 mins)
・Linking structlog context from Django to Celery (5 mins)
・Linking structlog context to Sentry (5 mins)
・Summary and Q&A (4 mins)