← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #180346]: Timestamp in logfile

 

Question #180346 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/180346

RaiMan posted a new comment:
@ Jason
Might be the time, to think about posting extra questions ;-)

It seems, that you are going into more complex structures.
So you have to think about the usage of classes, that would give you more flexibility and features.

Taking your example using a class (quick and dirty ;-):

==========================

# -------------------------- suite.sikuli
from sikuli import*

import logging # once at beginning of script
reload(logging)

# initialization
myHandler = logging.FileHandler('/Users/fitlab/SikuliLog/new.txt')
myLog = logging.getLogger()
myLog.addHandler(myHandler)
myLog.setLevel(logging.DEBUG)

from create import *

myLog.info('Calling Create script...')
aSafari = myApp("Safari", myLog)
aSafari.create()

# shutdown (a must in the IDE ! )
myHandler.close()

# -------------------------- create.sikuli
from sikuli import *

class myApp:

    def __init__(self, appname, myLogger = None):
        if appname:
            self.appname = appname
        else:
            self.appname = "no-app-given
        self.myLogger = myLogger
           
    def create(self):
       openApp(self.appname)
       if self.myLogger: self.myLogger.info("launch "+self.appname)

With this approach, you can enrich the class myApp with every
functionality you need and use it with every app. You might even create
a subclass with additional features for Safar (e.g. open an url).

On Top it makes sense, to wrap the logging into your own class, to get
more possibilities to control the logging in the different corners of
your solution.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.