简体   繁体   English

如何创建错误日志文件

[英]How to create log file to errors

I use pyinstaller3.1 to create a single executable file in windows. 我使用pyinstaller3.1在Windows中创建一个可执行文件。 If my code is wrong, will show 如果我的代码错误,将显示

"Fatal Error! return -1".

What can I do, like Py2exe. 我该怎么办,例如Py2exe。

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

If I user this methods like below, it creates "my_stderr.log" always. 如果我使用如下所示的方法,它将始终创建“ my_stderr.log”。 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 : 否则:使用简单的写日志文件中except部分:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 3:如何将警告和错误记录到日志文件? - Python 3: How to log warnings and errors to log file? 如何在不知道哪里会发生错误的情况下将输出和错误记录到文件中 - How to log outputs and errors to file without knowing where errors will occur 如何使用日志记录模块在日志文件中记录错误/异常? - How to log errors/exceptions in a log file using logging module? 如何将未处理的错误放入日志文件 - Python logging - How to put unhandled errors into a log file - Python logging 如何为python代码创建日志文件? - How to create a log file for a python code? 如何在python中的for循环中创建和写入日志文件 - How to create and write a log file in for loop in python 如何创建一个日志文件来记录python中的每个步骤? - How can a create a log file to log every steps in python? 解析日志文件并使用 python 中的表创建 CVS 报告。 由于某些原因,代码不断返回错误 - Parse a log file and create a CVS report with tables in python. The code keeps returning errors for some reasons 仅在实际发生错误的情况下,如何仅将python错误(stderr)保存到日志文件? - How to save python Errors (stderr) to a log file ONLY in case errors actually happen? 创建日志文件 - Create a log file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM