简体   繁体   中英

How to create log file to errors

I use pyinstaller3.1 to create a single executable file in windows. If my code is wrong, will show

"Fatal Error! return -1".

What can I do, like Py2exe.

http://www.py2exe.org/index.cgi/StderrLog

If I user this methods like below, it creates "my_stderr.log" always. I want to create the log file, only in executable file error.

import sys
sys.stderr = open("my_stderr.log",'w')

您可以将代码放入try-except块中,并且在缓存异常时可以打开文件以写入日志。

Use user-defined-exceptions to catch your own error

Else: Simply write a log file using in except part :

f = open("/path/to/file","a+") 
f.write("your message") 
f.close() 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM