一下文件执行将产生乱码,切.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")

经发现,是没有定义文件格式,修复后

'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:579817333 
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
import logging
def shop_logging(name):
    name = name+"登录成功!"
    logger = logging.getLogger()
    fh = logging.FileHandler("test.log",encoding="utf-8",mode="a")
    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”,mode=“a” 完美解决中文乱码的问题