django python 3.6 utf8输出

1)、settings.py 中配置Logging:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters':{
        'verbose': {
            'format':'[%(asctime)s] %(message)s'
        },
        'simple': {
            'format':'%(message)s'
        }
    },
    'handlers': {
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter':'verbose'
        },
        'dbg': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': '/tmp/test.log',
            'formatter':'verbose',
            'encoding': 'utf8'
        }
    },
    'loggers': {
        'mylog' : {
            'handlers': ['console','dbg'],
            'level': 'INFO'
        }
    }
}

2)、bytes 类型转utf8

           res(bytes 类型).decode('utf-8')

           bytes(s, encoding='utf-8')

            

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

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

 

猜你喜欢

转载自blog.csdn.net/ioniconline/article/details/84064879