Summary
In this chapter, we started by presenting the basic elements of logs. We defined how logs contain messages plus some metadata like a timestamp, and considered the different severity levels. We also described the need to define request IDs to group logs related to the same task. We also discussed how, in the Twelve-Factor App methodology, logs should be sent to stdout
to detach log generation from the process of handling and routing them to the proper destination to allow the collection of all logs in the system.
We then showed how to produce logs in Python using the standard logging
module, describing the three key elements of the logger
, the handler
, and the formatter
. Next, we showed the two different errors that can be produced in a system: expected, understood as errors that were foreseen as possible and are handled; and unexpected, meaning those that were not foreseen and occurred out of our control. We then went through the different strategies and cases for these...