Key Concepts

Review core concepts you need to learn to master this subject

Setting the Logging Level

import logging logger.setLevel(logging.INFO)

Setting the logging level for the logger object will allow all messages at and above that level to be produced in the output stream. The logging level can be set by using setLevel(). If no level is manually set, the default level logging.WARNING is used.

Logging in Python
Lesson 1 of 1
  1. 1
    Python includes a useful logging module within its standard library that allows for each event within an application to be logged and tracked. By logging messages, we can easily debug our software …
  2. 2
    The first step to utilizing the logging module is to import it into our application. We can do this using the following line of code: import logging Next, we can obtain our logger object using…
  3. 3
    When programming or debugging, we may want to focus on certain types of events. Lucky for us, there are defined logging levels that indicate specific levels of severity for a log message. Each logg…
  4. 4
    The logging module has several methods that we can use to log messages and errors with an assigned severity level. Those methods are: * debug(msg) which logs a message with level DEBUG * info(m…
  5. 5
    In the previous exercise checkpoint, you may have noticed that when we attempted to add DEBUG messages to our calculator application, they didn’t appear in the console. What’s going on here? Well…
  6. 6
    Up until now, we have used the console for our logged messages. The downside to this is that the logged messages are lost once the execution of the application finishes. There is another helpful st…
  7. 7
    The logging module provides some nifty capabilities to add several handlers to a single logger object. This means that we can easily direct our log messages to multiple streams, such as both a cons…
  8. 8
    A crucial benefit of using the logging module is the ability to format log messages. This allows us to include helpful information with each logged message, including: * timestamps * the module na…
  9. 9
    Now that we have covered all of the primary features of the logging module, let’s cover another method that allows for the configuration of some components in one easy step. The basicConfig() met…
  10. 10
    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…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo