Congratulations! You completed the Logging lesson! Within this lesson, we learned:
- The benefits of using the
loggingmodule over print statements
- How to create a logger object
- What log levels are
- How to log errors and messages with a given log level
- How to set the default log level
- How to log to the console, to a file, and to both
- How to format log messages
- How to simplify log configuration using
Let’s practice these concepts once more!
If you would like some extra practice, take a lookover script.py. Try playing around with the program to get a solid understanding of how it works. See if you can do any of the following:
Create a logger named
loggerthat will log to a file named
cashier.logand log all levels INFO and above.
Set formatting for the logger to match the following formatted log:2021-11-30 13:59:15,083 - __main__ - INFO - This is your log message!
Determine the appropriate log levels to log each of the following items and add log statements. to the code. Log the menu options. Log all values entered by the cashier. Log any caught exceptions. Log a message if the returned change is negative.
View the output of the