sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #25031
Re: [Question #245665]: Logging the errors and failures in a seperate file with line numbers where it is failed
Question #245665 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/245665
Status: Open => Answered
obiwan-92 proposed the following answer:
Hello,
Sorry. I was very busy the last two days.
I 'm not sure where the error is I don't have 42 lines in the code I
give you, so I presume you make some changes.
I resend to you the same code corrected :
import sys, traceback, datetime
def log(scr, str):
file = open(scr, 'a')
file.write(str)
file.close()
msg = ""
lscript = ['script1', 'script2'] # The list of the sikuli script you want to launch
NB = 10 # The number of time to loop on the scripts
flog = "C:/logfiel.txt" # the log file
for cpt in range(NB):
for scr in lscript:
t1 = datetime.datetime.now()
try:
m = __import__(scr, globals(), locals, [], -1)
if cpt > 0: reload(m)
t2 = datetime.datetime.now()
print scr + " OK"
log(flog, scr + " : OK in " +str((t2-t1).seconds)+'\n')
except FindFailed, Err:
t2 = datetime.datetime.now()
Err = str(Err).replace('\n', '').replace('!!WHILE IMPORTING!! ','')
for frame in traceback.extract_tb(sys.exc_info()[2]):
ferr,lerr,cerr,terr = frame
if scr+".py" in ferr:
msg = "\n\t in "+ferr+" ("+str(lerr)+") - time: "+str((t2-t1).seconds)
log(flog, "FindFailed : "+Err+" ! "+msg+'\n')
except BaseException, Err:
t2 = datetime.datetime.now()
Err = str(Err).replace('\n', '').replace('!!WHILE IMPORTING!! ','')
for frame in traceback.extract_tb(sys.exc_info()[2]):
ferr,lerr,cerr,terr = frame
if scr+".py" in ferr:
msg = "\n\t in "+ferr+" ("+str(lerr)+") - time: "+str((t2-t1).seconds)
log(flog, "BaseException : "+Err+" ! "+msg+'\n')
Have a nice day.
Regards.
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.