Log
Log
try:
# Perform some homework calculations
result = 10 / 0 # This will raise a ZeroDivisionError
except ZeroDivisionError:
logging.xxx('appropriate message', exc_info=False)
Explanation:
1. Import: create and import the logging module by a file to work with
logs.
2. Configuration:
o basicConfig sets up a basic logger.
o filename specifies the log file name.
o level sets the minimum log level to record (DEBUG in this case).
o format defines the structure of log messages.
3. Logging:
o We use logging.debug to record the start of the script.
4. Answer Questions:
a. Explain each log level ( DEBUG, INFO, WARNING, ERROR, CRITICAL)
and recommend retention for each. (____/2)
Configurability:
Performance:
Context:
Production Ready:
d. What is the default log level and filename write mode used by
Python logging? (____/2)
Default Log Level: WARNING
New log entries are added to the end of existing log files
Preserves historical log data across application restarts
References
Video
• Modern Python Logging (Video)
• Python Logging: How to Write Logs Like a Pro! (video)
• Python Tutorial: Logging Basics - Logging to Files, Setting Levels, and
Formatting (video)