Logging and reporting in Sikuli scripts

Created by RaiMan on
Last updated by:
RaiMan on

This from comment # 4 (Harry Riedinger https://launchpad.net/~temporary22)
of question https://answers.launchpad.net/sikuli/+question/165999

The python logging class is very easy to set up and I recommend using that for logging.

information on python logging is here: http://docs.python.org/library/logging.html

here is a quick, basic example of using logging:

import logging

# when run in IDE with reruns to avoid errors use
import logging; reload(logging)

#create a new logging instance
logger = logging.getLogger("MyLogger")

#set the file to log to

#set the logging level, DEBUG is the most verbose level

logger.info("We are starting now")

def functionInMyScript():
     logger.debug("entering functionInMyScript()")
     # do something that might fail
     logger.debug("leaving functionInMyScript()")

    logger.debug("Function call succeeded")
    logger.error("Function call failed")


You can also set up filters and log to different files depending on the log level.
Because logger uses handlers, you can do all this with a single logging instance.

It is a very flexible logging solution.