1.4 KiB
1.4 KiB
id, source_exercise_id, title, section, source_path, source_repo, source_commit, student_visible_solution, has_private_solution, skip
| id | source_exercise_id | title | section | source_path | source_repo | source_commit | student_visible_solution | has_private_solution | skip |
|---|---|---|---|---|---|---|---|---|---|
| practical-python-8.3 | 8.3 | Adding Logging to a Program | 8.2 Logging | 08_Testing_debugging/02_Logging.md | https://github.com/dabeaz-course/practical-python | 93dca856b41c61a0a0f85ae334116e4c125629ea | false | false | false |
Exercise 8.3: Adding Logging to a Program
Source: Practical Python Programming,
08_Testing_debugging/02_Logging.md.
Exercise 8.3: Adding Logging to a Program
To add logging to an application, you need to have some mechanism to initialize the logging module in the main module. One way to do this is to include some setup code that looks like this:
# This file sets up basic configuration of the logging module.
# Change settings here to adjust logging output as needed.
import logging
logging.basicConfig(
filename = 'app.log', # Name of the log file (omit to use stderr)
filemode = 'w', # File mode (use 'a' to append)
level = logging.WARNING, # Logging level (DEBUG, INFO, WARNING, ERROR, or CRITICAL)
)
Again, you'd need to put this someplace in the startup steps of your
program. For example, where would you put this in your report.py program?
Contents | Previous (8.1 Testing) | Next (8.3 Debugging)