Python3 使用 logging 模块输出日志中的中文乱码解决办法

创建filehandler的时候指定编码为utf-8

handler = logging.handlers.RotatingFileHandler(LOG_FILE, maxBytes=1024 * 1024, backupCount=5, encoding='utf-8')  # 实例化handler
2018-01-18 10:52:44,281 - INFO - ���������һ��
2018-01-18 10:52:44,281 - DEBUG - first debug message
2018-01-18 10:53:42,002 - INFO - ���������һ��
2018-01-18 10:53:42,003 - DEBUG - first debug message
2018-01-18 10:54:54,226 - INFO - ���������һ��
2018-01-18 10:54:54,226 - DEBUG - first debug message
2018-01-18 10:58:10,126 - INFO - 输出中文试一试
2018-01-18 10:58:10,126 - DEBUG - first debug message
2018-01-18 11:28:33,672 - INFO - 输出中文试一试
2018-01-18 11:28:33,672 - DEBUG - first debug message

python3中使用logging模块写日志,中文乱码,如何解决?
https://segmentfault.com/q/1010000010567904/

logging.handlers — Logging handlers
https://docs.python.org/3.6/library/logging.handlers.html

你可能感兴趣的:(Python基础)