I'm using Python 2.7 and pyinstaller to create a program. My program uses "print" to display the current progress of my program. What I want is for my program to create an error log in the event of an error, which will show the various statements that have printed to the screen so that I can see it's progress. Below is a simple program that will cause a zerodivisionerror:
import os
os.chdir("C:")
logname="Error 30032014 1832"
def subroutine():
print "Subroutine started"
print "Stage1 is complete"
print "Stage2 is complete"
a=1
b=0
c=a/b
subroutine()
This is the result:
Subroutine started
Stage1 is complete
Stage2 is complete
Traceback (most recent call last):
File "C:/Users/Joseph/Desktop/a.py", line 8, in <module>
subroutine()
File "C:/Users/Joseph/Desktop/a.py", line 7, in subroutine
c=a/b
ZeroDivisionError: integer division or modulo by zero
I want a textfile with the name logname (or if the name can be generated automatically with the date and time) to be generated displaying the above displayed information so that I can examine the error.