Learn

Congratulations! You completed the Logging lesson! Within this lesson, we learned:

  • The benefits of using the logging module 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 basicConfig()

Let’s practice these concepts once more!

Instructions

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:

  1. Create a logger named logger that will log to a file named cashier.log and 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!
  2. 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.

  3. View the output of the cashier.log file.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?