Python Logging - Tutorial
Summary
Highlights
Introduction and Log Levels00:00:02
The video begins by contrasting print debugging with persistent logging. It introduces Python's logging module and explains the five log levels: debug, info, warning, error, and critical, noting that by default only warning and above are output to the console.
Basic Configuration and File Logging00:01:32
The tutorial demonstrates how to import the logging module and use basicConfig to set the log level and direct output to a file using filename and filemode arguments, explaining that this configuration only runs once at the start of the program.
Custom Formatting00:05:47
The presenter shows how to change the format of logged messages using the format argument, adding attributes like ASC time for human-readable timestamps, levelname, and message to the log output.
Logging Variables and Exceptions00:07:35
This section covers how to log variable values using f-strings and how to log stack traces for exceptions using either exe info equals true within an error log or the dedicated exception method.
Custom Loggers and Handlers00:10:14
The final part explains creating custom loggers with getLogger to separate logs into different files, and configuring them using FileHandler and Formatter objects for more granular control over logging in larger projects.
Recently Summarized Articles
Related summaries
- Products I refuse to use (as a chemist)
- لوال - وقائع إعلان استقلال دولة قطر 1971م (الجزء الثاني)
- Isaac Asimov’s Terrifying Vision of the Afterlife | The Last Answer
- The End of Comcast As We Know It
- Reset Your Gut After Antibiotics (5 Simple Steps)
- Calm Your Mind in 16 Seconds | davidji’s Fast Stress Reset