Logging
Source: 12-Logging In Python/12.1-logging.ipynb
Start here — no coding background needed
What you will learn
Record what your program did — for debugging real apps.
In simple words
Instead of random prints, logging levels (info, error) keep production apps understandable.
Leave notes while programs run — helps find bugs in real projects.
Easy example — run this first. Change values and press Run again.
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Reference notes (from full bootcamp)
Optional — deeper detail for when you are ready
Python Logging
Logging is a crucial aspect of any application, providing a way to track events, errors, and operational information. Python's built-in logging module offers a flexible framework for emitting log messages from Python programs. In this lesson, we will cover the basics of logging, including how to configure logging, log levels, and best practices for using logging in Python applications.
Expected (from notebook): 2024-06-19 12:14:39 - root - DEBUG - This is a debug message 2024-06-19 12:14:39 - root - INFO - This is an info message 2024-06-19 12:14:39 - root - WARNING - This is a warning message 2024-06-19 12:14:39 - root - ERROR - This is an error message 2024-06-19 12:14:39 - root - CRITICAL - This is a critical message
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Log Levels
Python's logging module has several log levels indicating the severity of events. The default levels are:
- DEBUG: Detailed information, typically of interest only when diagnosing problems.
- INFO: Confirmation that things are working as expected.
- WARNING: An indication that something unexpected happened or indicative of some problem in the near future (e.g., ‘disk space low’). The software is still working as expected.
- ERROR: Due to a more serious problem, the software has not been able to perform some function.
- CRITICAL: A very serious error, indicating that the program itself may be unable to continue running.
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Practice test — try yourself
Write code, press Check. Wrong answer shows the correct code to copy & run.
You learned "Logging". Use print() to show: Done: Logging
Hint: Use one print() with the exact text.