Writing log messages to a log file

Asked by balakrishnan

**** this is a follow up of

https://answers.launchpad.net/sikuli/+question/184000

----------------------------------------------------------------------------

I want to copy all the log file into the notepad. After every line it should give the proper message like "the corresponding image is clicked ". But for me notepad is getting opened. But nothing is copied into that. Please help me..Below is my code.

def log(typ, msg):
    if loglevel >= 0 and typ == 0:
        print "[myinfo]", msg
    elif loglevel >= 1 and typ == 1:
       x=msg
        file.write(x)
    elif loglevel >= 2 and typ == 2:
        print "[myerror]", msg
loglevel = 2
file =open("C:\Users\Public\Videos\Desktop\log.txt","w")
log(0, "script started")
rightClick("1326118361937.png")
click("Manage.png")
click("DeviceManage.png")
doubleClick("Computer.png")
rightClick("ACPIMultipro.png")
def driver():
    click("Properties.png")
    click("Driver.png")
    sik = ("DriverVersio.png")
    m = find(sik).left(1).right(200)
    m.highlight(3)
    print m.text()
    click("1326120256234.png")
   driver()

Thanks
Balakrishnan.A.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

--- I cannot see in your script,
where you have: "But for me notepad is getting opened.". So how do you manage that?

--- You never write something to the log file
to the file () that could be opened with notepad, after the script has been run. Anyway, you should have a file.close() before the end of the script, to see all the written content, when running in IDE (the file may not be closed automatically).

I cannot see any log(1, "some text") in your script, which is the only case, something will be write to your log file.

--- After every line it should give the proper message like "the corresponding image is clicked "
Who else, than you yourself, should do that for you?
I cannot see any coding in your script, to accomplish that.

Revision history for this message
Mujeebu Rahman (mujeeburahman007) said :
#2

Hi Raiman,

Please could you suggest me the best way to use logging in sikuli. I wanted to log the errors and failures in a separate text file with line by line and the time stamp.

Regards,
Mujeeb

Revision history for this message
RaiMan (raimund-hocke) said :
#3

@Mujeebu
Debug. user(... some message ...)

Will produce:
[user timestamp] ... some message ...

... some message ... may contain %x according to Java's String.format(), that are placeholders for the values given in the comma seperated list after... some message ...

If you want to collect the user logs in a separate file:
Debug.setUserLogFile(... absolute filename ...)

... before the first log usage.

Can you help with this problem?

Provide an answer of your own, or ask balakrishnan for more information if necessary.

To post a message you must log in.