标签:mha ogg count 日志 str deb span put ESS
def regist(): name=input(‘name>>>:‘) pwd=input(‘pwd>>>:‘) dic={} dic[name] = pwd with open(‘xx‘,‘w‘,encoding=‘utf-8‘) as f: json.dump(dic,f,ensure_ascii=False) regist() import json # from xxx import regist import logging logger = logging.getLogger("登录日志")#获取一个新的日志 formatter = logging.Formatter(‘%(asctime)s - %(name)s - [%(lineno)d] - %(message)s‘)#时间 日志名字 行数 报错 ch = logging.StreamHandler()#生成一个屏幕流 fh = logging.FileHandler("购物车日志.log","w","utf-8")#生成一个文件流 ch.setFormatter(formatter)#把定义的模板添加给屏幕流 fh.setFormatter(formatter)#把定义的模板添加给文件流 # logger.setLevel(logging.DEBUG)#更改日志记录级别 logger.addHandler(ch)#将以屏幕流方式输出日志 logger.addHandler(fh)#将以文件流方式输出日志 def login(): count=0 num1=10 while count <3: with open(‘xx‘, ‘r‘, encoding=‘utf-8‘) as f: dic=json.load(f) num=input(‘name>>:‘) pwd=input(‘pwd>>>>:‘) if dic.get(num) and dic.get(num) == pwd: print(‘登录成功‘) break else: print(‘请重新输入‘) num1 +=100 count +=1 logger.error(f"登录失败,转账%s"%(num1)) login()
标签:mha ogg count 日志 str deb span put ESS
原文地址:https://www.cnblogs.com/LMTlmt/p/10311796.html