1.

Logging in Python

Answer»

Logging allows us to keep track of some events which occurs when some software runs. It becomes highly important in Software Development, Debugging and Running Softwares.

import logging
# Create and configues the logger
logging.basicConfig(filename="newfile.log", format='%(asctime)s %(message)s', filemode='w')
# Creates logging object
logg = logging.getLogger()
# Sets the level of logging to DEBUG
logg.setLevel(logging.DEBUG)
# Messages
logg.debug("Debug Message")
logger.warning("Its a Warning")
logger.info("Just an information")

Levels of Logging:

Described in order of increasing importance

LevelFunctionWhat it does
DEBUGlogging.debug()Used for tracking any events that occur during program execution
INFOlogging.info()Confirms the working of things at the end of the module in the program.
WARNINGlogging.warning()Used to flag some issues that might hinder the program from working in the future, but allows it to work for now.
ERRORlogging.error()Records errors that might have made the program fail at some point.
CRITICALlogging.critical()Indicates or flags fatal errors in the program.



Discussion

No Comment Found