Class Debug

java.lang.Object
org.sikuli.basics.Debug

public class Debug
extends 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 String logfile  
    static boolean shouldLogJython  
  • Constructor Summary

    Constructors 
    Constructor Description
    Debug()  
  • Method Summary

    Modifier and Type Method Description
    static void action​(String message, 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​(String message, Object... args)
    profile convenience: entering a method
    static void error​(String message, Object... args)
    Sikuli error messages
    switch on/off: always on
    static void exit​(String message, 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​(String message, Object... args)
    Deprecated. 
    static void info​(String message, 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​(String message)
    lap timer and print message with timer message
    log output depends on Settings.ProfileLogs
    static void log​(int level, String message, Object... args)
    Sikuli debug messages with level
    switch on/off: Settings.DebugLogs (off) and/or -Dsikuli.Debug
    static void log​(String message, Object... args)
    Sikuli debug messages with default level
    switch on/off: Settings.DebugLogs (off) and/or -Dsikuli.Debug
    static void logj​(String message, Object... args)  
    static boolean logJython()  
    static boolean logJython​(Boolean state)  
    static String logp​(String msg, Object... args)  
    static void logt​(String message)  
    static String logx​(int level, String message, Object... args)
    INTERNAL USE: special debug messages
    static void off()  
    static void on​(int level)  
    static void on​(String level)  
    static void out​(String msg)  
    static void profile​(String message, 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​(PrintStream rdo, 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​(String level)
    set debug level to given number value as string (ignored if invalid)
    static void setGlobalDebug​(int level)  
    static boolean setLogFile​(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​(Object logger)
    A logger object that is intended, to get Sikuli's log messages per redirection
    static boolean setLoggerAction​(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​(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​(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​(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​(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​(Object logger)
    same as setLogger(), but the Sikuli prefixes are omitted in all redirected messages
    static boolean setLoggerUser​(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​(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​(String message, Object... args)
    start timer with a message
    log output depends on Settings.ProfileLogs
    static void test​(String message, Object... args)
    Sikuli messages to use in tests
    switch on/off: always on
    static String trace​(String message, Object... args)  
    static void unsetWithTimeElapsed()  
    static void user​(String message, 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

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • 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​(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​(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​(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​(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​(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​(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​(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​(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​(PrintStream rdo, PrintStream rde)
    • out

      public static void out​(String msg)
    • setLogFile

      public static boolean setLogFile​(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​(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​(String level)
    • is

      public static boolean is​(int level)
    • is

      public static int is()
    • off

      public static void off()
    • setDebugLevel

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

      public static void action​(String message, 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​(String message, 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​(String message, 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​(String message, 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​(String message, 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​(String message, 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​(Boolean state)
    • logj

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

      public static void user​(String message, 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, String message, 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​(String message)
    • logx

      public static String logx​(int level, String message, 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 String logp​(String msg, Object... args)
    • trace

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

      public static void profile​(String message, 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​(String message, Object... args)
      profile convenience: entering a method
      Parameters:
      message - String or format string
      args - to use with format string
    • exit

      public static void exit​(String message, 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​(String message, 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​(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