【解决方案】logging: 中文log乱码

2019-09-29 17:44:10 浏览数 (1)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/weixin_40313634/article/details/100862296

问题代码:中文可能乱码

代码语言:javascript复制
logging.basicConfig(
    filename ='run.log',
    filemode = 'w',
    datefmt = '%d-%m-%Y %H%M%S',
    format = '%(asctime)s %(name)s: %(levelname)s: %(message)s',
    level = logging.INFO
)

修正后

代码语言:javascript复制
file = open('run.log', encoding="utf-8", mode="w")
logging.basicConfig(
    stream=file,
    datefmt = '%d-%m-%Y %H%M%S',
    format = '%(asctime)s %(name)s: %(levelname)s: %(message)s',
    level = logging.INFO
)

参考

0 人点赞