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
本文详细介绍了在Django项目中如何通过settings.py文件配置logging模块,包括不同级别的日志输出到控制台和文件,以及如何解决Python3中使用logging模块写日志时出现的中文乱码问题。

3万+

被折叠的 条评论
为什么被折叠?



