#对之前文件进行的增删改查操作实现日志操作,日志输出用户进行过的操作。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_objlogger=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 ') passdef delete(): logger.warning('this is delete operation') passdef change(): logger.error('this is changing operation') passdef scan(): logger.critical('this is scaning operation') passadd()delete()change()scan()