django python 3.6 utf8輸出
阿新 • • 發佈:2018-12-21
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