s5_day13作业
#对之前文件进行的增删改查操作实现日志操作,日志输出用户进行过的操作。 def log(): import logging logger_obj=logging.getLogger() logger_obj.setLevel(logging.INFO) fh=logging.FileHandler('log.txt') ch=logging.StreamHandler() logger_obj.addHandler(fh) logger_obj.addHandler(ch) formatter = logging.Formatter('%(asctime)s - %(name)s - %(message)s') fh.setFormatter(formatter) ch.setFormatter(formatter) return logger_obj logger=log() #函数赋值给变量,可以随意调用。 # logger.debug('*****************') # logger.info('this is adding operation ') # logger.warning('this is delete operation') # logger.error('this is changing operation') # logger.critical('this is scaning operation') def add(): logger.info('this is adding operation ') pass def delete(): logger.warning('this is delete operation') pass def change(): logger.error('this is changing operation') pass def scan(): logger.critical('this is scaning operation') pass add() delete() change() scan()