Logging is a very powerful way of validating your program executes correctly. In addition you can use it to debug your program.

You can log a process in your program using the module logging.

Online Courses
Python Crash Course: Master Python Programming

This message would be shown in the terminal.

import logging
logging.warning('Something went wrong.')

Levels of severity
There are several levels of severity: DEBUG, INFO, WARNING, ERROR, CRITICAL.
You can configure a minimum level of severity, if it’s lower than the set level it’s ignored.

import logging

logging.debug('Debug message')
logging.error('This is an error')

Another example:

import logging

logging.debug('Debug message')'Program started..')'Loading files')
logging.error('This is an error')

While developing you could set the severity level to logging.DEBUG which will show all messages. This will help you develop faster, find bugs quicker and so on.

Upon release of your program to the market you could set it to debugging.WARNING or debugging.ERROR.

import logging

Previous Post

Cookie policy | Privacy policy | ©