解决python logging 中文乱码问题

import logging

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)


if __name__ == '__main__':
    logger.info('测试')

 

posted @ 2021-02-20 09:13  Tiac  阅读(1903)  评论(0编辑  收藏  举报