[英]Log file not UTF-8
I am unable to get a log file in Python due to an error when attempting to open the file: The document was not UTF-8 valid.由于尝试打开文件时出现错误,我无法在 Python 中获取日志文件:文档不是 UTF-8 有效。
I have tried the following:我尝试了以下方法:
import logging
logging.basicConfig(filename='/home/pi/Desktop/logEL.log', filemode='w', format=u'%(asctime)s - %(message)s', level=logging.DEBUG, encoding='utf-8')
as well as:也:
import logging
root_logger= logging.getLogger()
root_logger.setLevel(logging.DEBUG) # or whatever
handler = logging.FileHandler('/home/pi/Desktop/logEL.log', 'a', 'utf-8')
formatter = logging.Formatter(u'%(asctime)s - %(message)s')
handler.setFormatter(formatter)
root_logger.addHandler(handler)
Opening the log file:打开日志文件:
Opening the log file with nano instead of the GUI seems to be the trick.使用 nano 而不是 GUI 打开日志文件似乎是诀窍。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.