Package org.sikuli.basics
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 !!!
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 Stringlogfilestatic booleanshouldLogJython -
Constructor Summary
Constructors Constructor Description Debug() -
Method Summary
Modifier and Type Method Description static voidaction(String message, Object... args)Sikuli messages from actions like click, ...
switch on/off: Settings.ActionLogslongend()stop timer and print timer message
log output depends on Settings.ProfileLogsstatic voidenter(String message, Object... args)profile convenience: entering a methodstatic voiderror(String message, Object... args)Sikuli error messages
switch on/off: always onstatic voidexit(String message, Object... args)profile convenience: exiting a methodstatic intgetDebugLevel()static voidglobalTraceOff()static voidglobalTraceOn()static voidhighlightOff()static voidhighlightOn()static voidhistory(String message, Object... args)Deprecated.static voidinfo(String message, Object... args)informative Sikuli messages
switch on/off: Settings.InfoLogsstatic voidinit()static intis()static booleanis(int level)static booleanisBeQuiet()static booleanisGlobalDebug()static booleanisGlobalTrace()static booleanisLogToFile()does Sikuli log go to a file?static booleanisStartWithTrace()static booleanisUserLogToFile()does user log go to a file?longlap(String message)lap timer and print message with timer message
log output depends on Settings.ProfileLogsstatic voidlog(int level, String message, Object... args)Sikuli debug messages with level
switch on/off: Settings.DebugLogs (off) and/or -Dsikuli.Debugstatic voidlog(String message, Object... args)Sikuli debug messages with default level
switch on/off: Settings.DebugLogs (off) and/or -Dsikuli.Debugstatic voidlogj(String message, Object... args)static booleanlogJython()static booleanlogJython(Boolean state)static Stringlogp(String msg, Object... args)static voidlogt(String message)static Stringlogx(int level, String message, Object... args)INTERNAL USE: special debug messagesstatic voidoff()static voidon(int level)static voidon(String level)static voidout(String msg)static voidprofile(String message, Object... args)Sikuli profiling messages
switch on/off: Settings.ProfileLogs, default offstatic voidquietOff()static voidquietOn()static voidreset()static voidresetGlobalDebug()static voidsaveRedirected(PrintStream rdo, PrintStream rde)static intsetDebugLevel()set debug level to default levelstatic voidsetDebugLevel(int level)set debug level to given valuestatic voidsetDebugLevel(String level)set debug level to given number value as string (ignored if invalid)static voidsetGlobalDebug(int level)static booleansetLogFile(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 filenamestatic voidsetLogger(Object logger)A logger object that is intended, to get Sikuli's log messages per redirectionstatic booleansetLoggerAction(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 messagestatic booleansetLoggerAll(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 textstatic booleansetLoggerDebug(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 messagestatic booleansetLoggerError(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 messagestatic booleansetLoggerInfo(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 messagestatic voidsetLoggerNoPrefix(Object logger)same as setLogger(), but the Sikuli prefixes are omitted in all redirected messagesstatic booleansetLoggerUser(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 messagestatic voidsetStartWithTrace()static booleansetUserLogFile(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 filenamestatic voidsetWithTimeElapsed()static voidsetWithTimeElapsed(long start)static booleanshouldHighlight()static DebugstartTimer()start timer
log output depends on Settings.ProfileLogsstatic DebugstartTimer(String message, Object... args)start timer with a message
log output depends on Settings.ProfileLogsstatic voidtest(String message, Object... args)Sikuli messages to use in tests
switch on/off: always onstatic Stringtrace(String message, Object... args)static voidunsetWithTimeElapsed()static voiduser(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
-
Field Details
-
shouldLogJython
public static boolean shouldLogJython -
logfile
-
-
Constructor Details
-
Debug
public Debug()
-
-
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
A logger object that is intended, to get Sikuli's log messages per redirection- Parameters:
logger- the logger object
-
setLoggerNoPrefix
same as setLogger(), but the Sikuli prefixes are omitted in all redirected messages- Parameters:
logger- the logger object
-
setLoggerAll
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
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
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
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
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
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
-
out
-
setLogFile
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
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
-
is
public static boolean is(int level) -
is
public static int is() -
off
public static void off() -
setDebugLevel
set debug level to given number value as string (ignored if invalid)- Parameters:
level- valid number string
-
action
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.use Debug.action() instead- Parameters:
message- String or format string (String.format)args- to use with format string
-
info
informative Sikuli messages
switch on/off: Settings.InfoLogs- Parameters:
message- String or format string (String.format)args- to use with format string
-
error
Sikuli error messages
switch on/off: always on- Parameters:
message- String or format string (String.format)args- to use with format string
-
test
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
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
-
logj
-
user
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
Sikuli debug messages with level
switch on/off: Settings.DebugLogs (off) and/or -Dsikuli.Debug- Parameters:
level- valuemessage- String or format string (String.format)args- to use with format string
-
logt
-
logx
INTERNAL USE: special debug messages- Parameters:
level- valuemessage- text or format stringargs- for use with format string- Returns:
- generated message
-
logp
-
trace
-
profile
Sikuli profiling messages
switch on/off: Settings.ProfileLogs, default off- Parameters:
message- String or format stringargs- to use with format string
-
enter
profile convenience: entering a method- Parameters:
message- String or format stringargs- to use with format string
-
exit
profile convenience: exiting a method- Parameters:
message- String or format stringargs- to use with format string
-
startTimer
start timer
log output depends on Settings.ProfileLogs- Returns:
- timer
-
startTimer
start timer with a message
log output depends on Settings.ProfileLogs- Parameters:
message- String or format stringargs- 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
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
-