I\'m trying to decipher the information contained in my logs (the logging setup is using the default formatter). The documentation states:
Do formatting f
Here is the example of an advanced way of logging:-
import logging
class logger_con():
def log_test(self):
"""
:create logger
:set logger level
:create console handler
:add formatter to console handler
:add console handler to logger
:add logging massage
:return:
"""
#create logger and set level
logger=logging.getLogger(logger_con.__name__)
logger.setLevel(logging.INFO)
#create console handler(we are using steamHandler which is only used to display log in console)
con_handler=logging.StreamHandler()
con_handler.setLevel(logging.INFO)
#create formatter and add formatter to con_handler
formatter=logging.Formatter('%(asctime)s : %(message)s : %(levelname)s -%(name)s',datefmt='%d%m%Y %I:%M:%S %p')
con_handler.setFormatter(formatter)
#add console handler to logger
logger.addHandler(con_handler)
logger.debug('Program debugging')
logger.info('massage conatain information')
logger.warning('warning message')
logger.error('massage contains error')
logger.critical('critical massages')