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.
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.basicConfig(level=logging.WARNING) logging.debug('Debug message') logging.error('This is an error')
import logging logging.basicConfig(level=logging.ERROR) logging.debug('Debug message') logging.info('Program started..') logging.info('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 logging.basicConfig(level=logging.WARNING)