CharlesPikachu / musicdl

Musicdl: A lightweight music downloader written in pure python.
https://musicdl.readthedocs.io/
Apache License 2.0
1.18k stars 270 forks source link

[BUG] 写入log文件,中文编码为GBK #18

Closed lingr7 closed 2 years ago

lingr7 commented 2 years ago

Environment (使用环境)

Question description (问题描述) musicdl/modules/utils/logger.py中,将log写入文件,写入中文时,使用的是GBK 编码,如何指定为UTF-8编码?

    def info(self, message, disable_print=False):
        if disable_print:
            fp = open(self.logfilepath, 'a')
            fp.write(message + '\n')
        else:
            Logger.log(logging.INFO, message)

Screenshot (报错截图) image

Advice (修复建议) 添加指定编码的选项或参数。

AlieZVzz commented 2 years ago

fp = open(self.logfilepath, 'a', encoding="utf-8")

lingr7 commented 2 years ago

测试过,未生效。

CharlesPikachu commented 2 years ago

第三十七行: logging.FileHandler(logfilepath, encoding='utf-8') 指定一下编码为utf-8,后续版本我会把这个设置成默认utf-8的

lingr7 commented 2 years ago

image 已经生效,就是这个esc的有点别扭。