⼀下⽂件执⾏将产⽣乱码,切.log⽂件显⽰问好,打不开
import logging
def shop_logging(name):
name = name+\"登录成功!\" logger = logging.getLogger()
fh = logging.FileHandler(\"test.log\")
formatter = logging.Formatter(\"%(asctime)s - %(name)s-%(levelname)s %(message)s\") fh.setFormatter(formatter) logger.addHandler(fh)
logger.setLevel(logging.DEBUG) logger.info(name)shop_logging(\"auxc\")
经发现,是没有定义⽂件格式,修复后
import logging
def shop_logging(name):
name = name+\"登录成功!\" logger = logging.getLogger()
fh = logging.FileHandler(\"test.log\
formatter = logging.Formatter(\"%(asctime)s - %(name)s-%(levelname)s %(message)s\") fh.setFormatter(formatter) logger.addHandler(fh)
logger.setLevel(logging.DEBUG) logger.info(name)shop_logging(\"auxc\")
加上 encoding=\"utf-8\完美解决中⽂乱码的问题
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
因篇幅问题不能全部显示,请点此查看更多更全内容