Class Debug


  • public class Debug
    extends java.lang.Object
    Debug is a utility class that wraps println statements and allows more or less command line output to be turned on.

    For debug messages only ( Debug.log() ):
    Use system property: sikuli.Debug to set the debug level (default = 1)
    On the command line, use -Dsikuli.Debug=n to set it to level n
    -Dsikuli.Debug will disable any debug messages
    (which is equivalent to using Settings.Debuglogs = false)

    It prints if the level number is less than or equal to the currently set DEBUG_LEVEL.

    For messages ActionLogs, InfoLogs see Settings

    You might send all messages generated by this class to a file:
    -Dsikuli.Logfile=pathname (no path given: SikuliLog.txt in working folder)
    This can be restricted to Debug.user only (others go to System.out):
    -Dsikuli.LogfileUser=pathname (no path given: UserLog.txt in working folder)

    You might redirect info, action, error and debug messages to your own logger object
    Start with setLogger() and then define with setLoggerXyz() the redirection targets

    This solution is NOT threadsafe !!!

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String logfile  
      static boolean shouldLogJython  
    • Constructor Summary

      Constructors 
      Constructor Description
      Debug()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void action​(java.lang.String message, java.lang.Object... args)
      Sikuli messages from actions like click, ...
      switch on/off: Settings.ActionLogs
      long end()
      stop timer and print timer message
      log output depends on Settings.ProfileLogs
      static void enter​(java.lang.String message, java.lang.Object... args)
      profile convenience: entering a method
      static void error​(java.lang.String message, java.lang.Object... args)
      Sikuli error messages
      switch on/off: always on
      static void exit​(java.lang.String message, java.lang.Object... args)
      profile convenience: exiting a method
      static int getDebugLevel()  
      static void globalTraceOff()  
      static void globalTraceOn()  
      static void highlightOff()  
      static void highlightOn()  
      static void history​(java.lang.String message, java.lang.Object... args)
      Deprecated. 
      static void info​(java.lang.String message, java.lang.Object... args)
      informative Sikuli messages
      switch on/off: Settings.InfoLogs
      static void init()  
      static int is()  
      static boolean is​(int level)  
      static boolean isBeQuiet()  
      static boolean isGlobalDebug()  
      static boolean isGlobalTrace()  
      static boolean isLogToFile()
      does Sikuli log go to a file?
      static boolean isStartWithTrace()  
      static boolean isUserLogToFile()
      does user log go to a file?
      long lap​(java.lang.String message)
      lap timer and print message with timer message
      log output depends on Settings.ProfileLogs
      static void log​(int level, java.lang.String message, java.lang.Object... args)
      Sikuli debug messages with level
      switch on/off: Settings.DebugLogs (off) and/or -Dsikuli.Debug
      static void log​(java.lang.String message, java.lang.Object... args)
      Sikuli debug messages with default level
      switch on/off: Settings.DebugLogs (off) and/or -Dsikuli.Debug
      static void logCallStack​(int level, java.lang.String message)  
      static void logj​(java.lang.String message, java.lang.Object... args)  
      static boolean logJython()  
      static boolean logJython​(java.lang.Boolean state)  
      static java.lang.String logp​(java.lang.String msg, java.lang.Object... args)  
      static void logt​(java.lang.String message)  
      static java.lang.String logx​(int level, java.lang.String message, java.lang.Object... args)
      INTERNAL USE: special debug messages
      static void off()  
      static void on​(int level)  
      static void on​(java.lang.String level)  
      static void out​(java.lang.String msg)  
      static void profile​(java.lang.String message, java.lang.Object... args)
      Sikuli profiling messages
      switch on/off: Settings.ProfileLogs, default off
      static void quietOff()  
      static void quietOn()  
      static void reset()  
      static void resetGlobalDebug()  
      static void saveRedirected​(java.io.PrintStream rdo, java.io.PrintStream rde)  
      static int setDebugLevel()
      set debug level to default level
      static void setDebugLevel​(int level)
      set debug level to given value
      static void setDebugLevel​(java.lang.String level)
      set debug level to given number value as string (ignored if invalid)
      static void setGlobalDebug​(int level)  
      static boolean setLogFile​(java.lang.String fileName)
      specify, where the logs should be written:
      null - use from property sikuli.Logfile empty - use SikuliLog.txt in working folder not empty - use given filename
      static void setLogger​(java.lang.Object logger)
      A logger object that is intended, to get Sikuli's log messages per redirection
      static boolean setLoggerAction​(java.lang.String mAction)
      specify the target method for redirection of Sikuli's action messages [log]
      must be the name of an instance method of the previously defined logger and
      must accept exactly one string parameter, that contains the info message
      static boolean setLoggerAll​(java.lang.String mAll)
      sets the redirection for all message types user, info, action, error and debug must be the name of an instance method of the previously defined logger and
      must accept exactly one string parameter, that contains the message text
      static boolean setLoggerDebug​(java.lang.String mDebug)
      specify the target method for redirection of Sikuli's debug messages [debug]
      must be the name of an instance method of the previously defined logger and
      must accept exactly one string parameter, that contains the info message
      static boolean setLoggerError​(java.lang.String mError)
      specify the target method for redirection of Sikuli's error messages [error]
      must be the name of an instance method of the previously defined logger and
      must accept exactly one string parameter, that contains the info message
      static boolean setLoggerInfo​(java.lang.String mInfo)
      specify the target method for redirection of Sikuli's info messages [info]
      must be the name of an instance method of the previously defined logger and
      must accept exactly one string parameter, that contains the info message
      static void setLoggerNoPrefix​(java.lang.Object logger)
      same as setLogger(), but the Sikuli prefixes are omitted in all redirected messages
      static boolean setLoggerUser​(java.lang.String mUser)
      specify the target method for redirection of Sikuli's user log messages [user]
      must be the name of an instance method of the previously defined logger and
      must accept exactly one string parameter, that contains the info message
      static void setStartWithTrace()  
      static boolean setUserLogFile​(java.lang.String fileName)
      specify, where the user logs (Debug.user) should be written:
      null - use from property sikuli.LogfileUser empty - use UserLog.txt in working folder not empty - use given filename
      static void setWithTimeElapsed()  
      static void setWithTimeElapsed​(long start)  
      static boolean shouldHighlight()  
      static Debug startTimer()
      start timer
      log output depends on Settings.ProfileLogs
      static Debug startTimer​(java.lang.String message, java.lang.Object... args)
      start timer with a message
      log output depends on Settings.ProfileLogs
      static void test​(java.lang.String message, java.lang.Object... args)
      Sikuli messages to use in tests
      switch on/off: always on
      static java.lang.String trace​(java.lang.String message, java.lang.Object... args)  
      static void unsetWithTimeElapsed()  
      static void user​(java.lang.String message, java.lang.Object... args)
      messages given by the user
      switch on/off: Settings.UserLogs
      depending on Settings.UserLogTime, the prefix contains a timestamp
      the user prefix (default "user") can be set: Settings,UserLogPrefix
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • shouldLogJython

        public static boolean shouldLogJython
      • logfile

        public static java.lang.String logfile
    • Constructor Detail

      • Debug

        public Debug()
    • Method Detail

      • init

        public static void init()
      • isGlobalDebug

        public static boolean isGlobalDebug()
      • setGlobalDebug

        public static void setGlobalDebug​(int level)
      • resetGlobalDebug

        public static void resetGlobalDebug()
      • highlightOn

        public static void highlightOn()
      • highlightOff

        public static void highlightOff()
      • shouldHighlight

        public static boolean shouldHighlight()
      • quietOn

        public static void quietOn()
      • quietOff

        public static void quietOff()
      • isBeQuiet

        public static boolean isBeQuiet()
      • isStartWithTrace

        public static boolean isStartWithTrace()
      • setStartWithTrace

        public static void setStartWithTrace()
      • globalTraceOn

        public static void globalTraceOn()
      • globalTraceOff

        public static void globalTraceOff()
      • isGlobalTrace

        public static boolean isGlobalTrace()
      • reset

        public static void reset()
      • setWithTimeElapsed

        public static void setWithTimeElapsed()
      • setWithTimeElapsed

        public static void setWithTimeElapsed​(long start)
      • unsetWithTimeElapsed

        public static void unsetWithTimeElapsed()
      • setLogger

        public static void setLogger​(java.lang.Object logger)
        A logger object that is intended, to get Sikuli's log messages per redirection
        Parameters:
        logger - the logger object
      • setLoggerNoPrefix

        public static void setLoggerNoPrefix​(java.lang.Object logger)
        same as setLogger(), but the Sikuli prefixes are omitted in all redirected messages
        Parameters:
        logger - the logger object
      • setLoggerAll

        public static boolean setLoggerAll​(java.lang.String mAll)
        sets the redirection for all message types user, info, action, error and debug must be the name of an instance method of the previously defined logger and
        must accept exactly one string parameter, that contains the message text
        Parameters:
        mAll - name of the method where the message should be sent
        Returns:
        true if the method is available false otherwise
      • setLoggerUser

        public static boolean setLoggerUser​(java.lang.String mUser)
        specify the target method for redirection of Sikuli's user log messages [user]
        must be the name of an instance method of the previously defined logger and
        must accept exactly one string parameter, that contains the info message
        Parameters:
        mUser - name of the method where the message should be sent
        reset to default logging by either null or empty string
        Returns:
        true if the method is available false otherwise
      • setLoggerInfo

        public static boolean setLoggerInfo​(java.lang.String mInfo)
        specify the target method for redirection of Sikuli's info messages [info]
        must be the name of an instance method of the previously defined logger and
        must accept exactly one string parameter, that contains the info message
        Parameters:
        mInfo - name of the method where the message should be sent
        reset to default logging by either null or empty string
        Returns:
        true if the method is available false otherwise
      • setLoggerAction

        public static boolean setLoggerAction​(java.lang.String mAction)
        specify the target method for redirection of Sikuli's action messages [log]
        must be the name of an instance method of the previously defined logger and
        must accept exactly one string parameter, that contains the info message
        Parameters:
        mAction - name of the method where the message should be sent
        reset to default logging by either null or empty string
        Returns:
        true if the method is available false otherwise
      • setLoggerError

        public static boolean setLoggerError​(java.lang.String mError)
        specify the target method for redirection of Sikuli's error messages [error]
        must be the name of an instance method of the previously defined logger and
        must accept exactly one string parameter, that contains the info message
        Parameters:
        mError - name of the method where the message should be sent
        reset to default logging by either null or empty string
        Returns:
        true if the method is available false otherwise
      • setLoggerDebug

        public static boolean setLoggerDebug​(java.lang.String mDebug)
        specify the target method for redirection of Sikuli's debug messages [debug]
        must be the name of an instance method of the previously defined logger and
        must accept exactly one string parameter, that contains the info message
        Parameters:
        mDebug - name of the method where the message should be sent
        reset to default logging by either null or empty string
        Returns:
        true if the method is available false otherwise
      • saveRedirected

        public static void saveRedirected​(java.io.PrintStream rdo,
                                          java.io.PrintStream rde)
      • out

        public static void out​(java.lang.String msg)
      • setLogFile

        public static boolean setLogFile​(java.lang.String fileName)
        specify, where the logs should be written:
        null - use from property sikuli.Logfile empty - use SikuliLog.txt in working folder not empty - use given filename
        Parameters:
        fileName - null, empty or absolute filename
        Returns:
        success
      • isLogToFile

        public static boolean isLogToFile()
        does Sikuli log go to a file?
        Returns:
        true if yes, false otherwise
      • setUserLogFile

        public static boolean setUserLogFile​(java.lang.String fileName)
        specify, where the user logs (Debug.user) should be written:
        null - use from property sikuli.LogfileUser empty - use UserLog.txt in working folder not empty - use given filename
        Parameters:
        fileName - null, empty or absolute filename
        Returns:
        success
      • isUserLogToFile

        public static boolean isUserLogToFile()
        does user log go to a file?
        Returns:
        true if yes, false otherwise
      • getDebugLevel

        public static int getDebugLevel()
        Returns:
        current debug level
      • setDebugLevel

        public static int setDebugLevel()
        set debug level to default level
        Returns:
        default level
      • setDebugLevel

        public static void setDebugLevel​(int level)
        set debug level to given value
        Parameters:
        level - value
      • on

        public static void on​(int level)
      • on

        public static void on​(java.lang.String level)
      • is

        public static boolean is​(int level)
      • is

        public static int is()
      • off

        public static void off()
      • setDebugLevel

        public static void setDebugLevel​(java.lang.String level)
        set debug level to given number value as string (ignored if invalid)
        Parameters:
        level - valid number string
      • action

        public static void action​(java.lang.String message,
                                  java.lang.Object... args)
        Sikuli messages from actions like click, ...
        switch on/off: Settings.ActionLogs
        Parameters:
        message - String or format string (String.format)
        args - to use with format string
      • history

        @Deprecated
        public static void history​(java.lang.String message,
                                   java.lang.Object... args)
        Deprecated.
        use Debug.action() instead
        Parameters:
        message - String or format string (String.format)
        args - to use with format string
      • info

        public static void info​(java.lang.String message,
                                java.lang.Object... args)
        informative Sikuli messages
        switch on/off: Settings.InfoLogs
        Parameters:
        message - String or format string (String.format)
        args - to use with format string
      • error

        public static void error​(java.lang.String message,
                                 java.lang.Object... args)
        Sikuli error messages
        switch on/off: always on
        Parameters:
        message - String or format string (String.format)
        args - to use with format string
      • test

        public static void test​(java.lang.String message,
                                java.lang.Object... args)
        Sikuli messages to use in tests
        switch on/off: always on
        Parameters:
        message - String or format string (String.format)
        args - to use with format string
      • log

        public static void log​(java.lang.String message,
                               java.lang.Object... args)
        Sikuli debug messages with default level
        switch on/off: Settings.DebugLogs (off) and/or -Dsikuli.Debug
        Parameters:
        message - String or format string (String.format)
        args - to use with format string
      • logJython

        public static boolean logJython()
      • logJython

        public static boolean logJython​(java.lang.Boolean state)
      • logj

        public static void logj​(java.lang.String message,
                                java.lang.Object... args)
      • user

        public static void user​(java.lang.String message,
                                java.lang.Object... args)
        messages given by the user
        switch on/off: Settings.UserLogs
        depending on Settings.UserLogTime, the prefix contains a timestamp
        the user prefix (default "user") can be set: Settings,UserLogPrefix
        Parameters:
        message - String or format string (String.format)
        args - to use with format string
      • log

        public static void log​(int level,
                               java.lang.String message,
                               java.lang.Object... args)
        Sikuli debug messages with level
        switch on/off: Settings.DebugLogs (off) and/or -Dsikuli.Debug
        Parameters:
        level - value
        message - String or format string (String.format)
        args - to use with format string
      • logt

        public static void logt​(java.lang.String message)
      • logCallStack

        public static void logCallStack​(int level,
                                        java.lang.String message)
      • logx

        public static java.lang.String logx​(int level,
                                            java.lang.String message,
                                            java.lang.Object... args)
        INTERNAL USE: special debug messages
        Parameters:
        level - value
        message - text or format string
        args - for use with format string
        Returns:
        generated message
      • logp

        public static java.lang.String logp​(java.lang.String msg,
                                            java.lang.Object... args)
      • trace

        public static java.lang.String trace​(java.lang.String message,
                                             java.lang.Object... args)
      • profile

        public static void profile​(java.lang.String message,
                                   java.lang.Object... args)
        Sikuli profiling messages
        switch on/off: Settings.ProfileLogs, default off
        Parameters:
        message - String or format string
        args - to use with format string
      • enter

        public static void enter​(java.lang.String message,
                                 java.lang.Object... args)
        profile convenience: entering a method
        Parameters:
        message - String or format string
        args - to use with format string
      • exit

        public static void exit​(java.lang.String message,
                                java.lang.Object... args)
        profile convenience: exiting a method
        Parameters:
        message - String or format string
        args - to use with format string
      • startTimer

        public static Debug startTimer()
        start timer
        log output depends on Settings.ProfileLogs
        Returns:
        timer
      • startTimer

        public static Debug startTimer​(java.lang.String message,
                                       java.lang.Object... args)
        start timer with a message
        log output depends on Settings.ProfileLogs
        Parameters:
        message - String or format string
        args - to use with format string
        Returns:
        timer
      • end

        public long end()
        stop timer and print timer message
        log output depends on Settings.ProfileLogs
        Returns:
        the time in msec
      • lap

        public long lap​(java.lang.String message)
        lap timer and print message with timer message
        log output depends on Settings.ProfileLogs
        Parameters:
        message - String or format string
        Returns:
        the time in msec