class encapsulates the automated web log

The log # 
Import the logging
from Common Import contants

class the Log:
DEF the __init __ (Self):
# create log collector
self.logger = logging.getLogger ( 'new_logger')
self.logger.setLevel ( 'the DEBUG')

# define input channel
fh = logging.FileHandler (contants.case_log, mode = ' a', encoding = 'utf-8') # output to a log file
CH = logging.StreamHandler ()

# log output level defined
fh.setLevel ( 'the INFO')
CH. setLevel ( 'ERROR')

# define the output format
formatter = logging.Formatter ( '% (asctime ) s -% (filename) s -% (name) s -% (levelname) s - log information:% (message) s' )
fh.setFormatter (Formatter)
CH.setFormatter (Formatter)

# log docking channels
self.logger.addHandler(fh)
self.logger.addHandler(ch)

def get_log(self, level, msg):

if level == 'DEBUG':
self.logger.debug(msg)
elif level == 'INFO':
self.logger.info(msg)
elif level == 'WARNING':
self.logger.warning(msg)
elif level == 'ERROR':
self.logger.error(msg)
elif level == 'CRITICAL':
self.logger.critical(msg)

def log_debug(self, msg):
return self.get_log('DEBUG', msg)

def log_info(self, msg):
return self.get_log('INFO', msg)

def log_warning(self, msg):
self.get_log return ( 'the WARNING', MSG)

DEF log_error action (Self, MSG):
return self.get_log ( 'ERROR', MSG)

DEF log_critical (Self, MSG):
return self.get_log ( 'CRITICAL in', MSG)

IF __ == __name__ '__ main__':
log = the log ()
log.log_debug ( 'which is debug information')
log.log_info ( 'information which is info')
log.log_warning ( 'information which is waring')
log.log_error ( ' this is the error message ')
log.log_critical (' this is critical information ')


Guess you like

Origin www.cnblogs.com/sophia-985935365/p/12640023.html