Logging sikuli errors to a separate log file

Asked by stewazy on 2017-04-05

Hello everyone, I'm new to sikuli, I'm bound by the framework which has been developed on 1.0.1 sikuli and I have to find a way to export sikuli errors to a separate log file. For example on which line the test failed and where was the problem. I made a simple file writer:

file = open(logFile, 'a')
file.write(message)
file.close()

Now I would like a way to write to that log file the errors generated by sikuli. Can someone point me to the right way? I have been reading on python error and sikuli docs but I am unable to find a way.

Thank you for your support in advance.

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2017-04-07
Last query:
2017-04-07
Last reply:
2017-04-07

This question was reopened

RaiMan (raimund-hocke) said : #1

The print output produced by Sikuli is simply going to stdout.

if it is a must, to stick with 1.0.1, then these are your options:

Just run the script from commandline and pipe the output to a file (>> operator).
then you might mix in your own messages using print

The other option is to completely switch off the Sikuli messages and setup your own logging like you mentioned above.
Use the different options, to deal with FindFailed or other exceptions with try...except... where you could write according messages to your file.

stewazy (stewazy) said : #2

FindFaild is this like Exception e for example in java, can i write FindFailed into my log file ?

for example

def myTest()
try:
      do test
exception FindFailed:
     f= open(file,'a')
      f.write(FindFailed)
     f.close()

?

stewazy (stewazy) said : #3

e = sys.exc_info() smth in these lines in except but i still can't make it to tell me which line in my code failed any ideas, guys im very close to my solution :D

stewazy (stewazy) said : #5

Thanks RaiMan, that solved my question.

stewazy (stewazy) said : #6

Tank you @RaiMan You are a God among men :D

here is my solution for logging error

try:
    #your test

except:
    var = traceback.format_exc()

    file = open("C:\\Sikuli\\log.log", 'a')
    file.write(var)
    file.close()

RaiMan (raimund-hocke) said : #7

thanks for the kind feedback ;-)
... but it is only some steps of experience ahead.

stewazy (stewazy) said : #8

Here I am again with a problem, now my xmlrunner isn't working, :S every TC passes now :S can you recommend an xml runner which I can use ?

Best RaiMan (raimund-hocke) said : #9

please get used to starting a new question when you have a new topic.

last exception ;-)
see faq 1804

stewazy (stewazy) said : #10

Thanks RaiMan, that solved my question.

stewazy (stewazy) said : #11

Sry :((( but thnx :D