In this article, we are going to learn how to track event records.
while writing code we use the print statement to know the sequence of run the code. obviously, python is an interpreted language but sometimes we stuck in the problem and we do not get the actual cause. we use print statements. printing statements to validate the code is not a convenient way. it may solve simple program problems but for the complex program in software development is not efficient. if we track the record of error, warning then it takes less time to build software. for software, development dubbing is the most important. if you have a good command of dubbing then you build errorless software.
Python has built-in module logging. hence no need to install it. this module defines functions and classes which implement flexible event logging system for applications and libraries. there is six-level of logging.
Logging provides a set of convenience functions for simple logging usage. These are debug(),info(),error(),warning(),critical(). logging functions are named after the logging level or severity of events they are used to track.
- CRITICAL - Represents a very serious need for high attention
- ERROR- Represents serious error, the software has not been able to perform some operations.
- WARNING - Represents a warning message, some caution is needed.
- INFO - Represents a message with some important information.
- DEBUG - Represents a message with dubbing information
- NOTSET - Represents that level is not set.
- logging.debug() - Use to very detailed output for diagnostic problem.
- logging.info() - Report events that occur during normal operation of the program.
- logging.warning() - Issues the warning regarding particular runtime event
- logging.critical() - As appropriate for the specific error and application domain
# import logging module
# just test which message print out on the console
logging.debug('this is debug message')
logging.info('this is info meaage')
logging.warning('this is warning message')
logging.error('this is error message')
logging.critical('this is the critical message')
PS C:Usersadminproject> python intro.py
WARNING:root:this is warning message
ERROR:root:this is error message
CRITICAL:root:this is the critical message
The printed message includes the indication of the level and the description of the event provided in the logging call.
debug and info messages are not print out on the console because the default level is WARNING.
hence warning and all greater than warning level print out on console.