即時通訊目前通過......Python的異常記錄
def log_message(text):
log_file = "/var/log/logfile.txt"
try:
if os.path.isfile(log_file):
mode = "a"
else:
mode = "w"
with open(log_file, mode) as myfile:
myfile.write("%s\n" % (text))
return True
except Exception as e:
print "error : ",e
return False
try:
... some code
except Exception as e:
log_message("error : %s" % (e))
但是即時通訊我的日誌我得到記錄程序的異常「類型錯誤:類型的參數‘NoneType’不是可迭代的」 有沒有一種辦法還會記錄下例外的其他信息。如行號模塊文件等等?
>>> post_builder_ghost(abc).generate()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "post_builder.py", line 34, in generate
if 'youtube' in self.video:
TypeError: argument of type 'NoneType' is not iterable
>>>
感謝,
爲什麼不試試['logging'(https://docs.python.org/2/library/logging.html)模塊 – emeth