Package weka.core
Class Debug
- java.lang.Object
-
- weka.core.Debug
-
- All Implemented Interfaces:
java.io.Serializable,RevisionHandler
public class Debug extends java.lang.Object implements java.io.Serializable, RevisionHandler
A helper class for debug output, logging, clocking, etc.- Version:
- $Revision: 7519 $
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDebug.ClockA little helper class for clocking and outputting times.static classDebug.DBOcontains debug methodsstatic classDebug.LogA helper class for logging stuff.static classDebug.RandomThis extended Random class enables one to print the generated random numbers etc., before they are returned.static classDebug.SimpleLogA little, simple helper class for logging stuff.static classDebug.TimestampA class that can be used for timestamps in files, The toString() method simply returns the associated Date object in a timestamp format.
-
Field Summary
Fields Modifier and Type Field Description static java.util.logging.LevelALLthe log level Allstatic java.util.logging.LevelCONFIGthe log level Vonfigstatic java.util.logging.LevelFINEthe log level Finestatic java.util.logging.LevelFINERthe log level Finerstatic java.util.logging.LevelFINESTthe log level Fineststatic java.util.logging.LevelINFOthe log level Infostatic java.util.logging.LevelOFFthe log level Off - i.e., no loggingstatic java.util.logging.LevelSEVEREthe log level Severestatic java.util.logging.LevelWARNINGthe log level Warning
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Debug.ClockgetClock()returns the instance of the Clock that is internally usedstatic java.lang.StringgetCurrentDir()returns the current working directory of the userbooleangetEnabled()returns whether the logging is enabledstatic java.lang.StringgetHomeDir()returns the home directory of the userjava.lang.StringgetRevision()Returns the revision string.static java.lang.StringgetTempDir()returns the system temp directorystatic java.lang.ObjectloadFromFile(java.lang.String filename)deserializes the content of the file and returns it, null if an error occurred.voidlog(java.lang.String message)prints the given message with level INFOvoidlog(java.util.logging.Level level, java.lang.String message)prints the given message with the specified level and an empty sourceclassvoidlog(java.util.logging.Level level, java.lang.String sourceclass, java.lang.String message)prints the given message with the specified levelvoidlog(java.util.logging.Level level, java.lang.String sourceclass, java.lang.String sourcemethod, java.lang.String message)prints the given message with the specified levelstatic Debug.ClocknewClock()returns a new instance of a clockstatic Debug.LognewLog(java.lang.String filename, int size, int numFiles)returns a new Log instancestatic java.util.RandomnewRandom()returns a default debug random object, with no particular seed and debugging enabled.static java.util.RandomnewRandom(int seed)returns a debug random object with the specified seed and debugging enabled.static Debug.TimestampnewTimestamp()returns a default timestamp for the current date/timestatic booleansaveToFile(java.lang.String filename, java.lang.Object o)writes the serialized object to the speicified filevoidsetEnabled(boolean value)sets whether the logging is enabled or notvoidstartClock()starts the clockvoidstopClock(java.lang.String message)stops the clock and prints the message associated with the time, but only if the logging is enabled.static java.util.logging.LevelstringToLevel(java.lang.String level)turns the string representing a level, e.g., "FINE" or "ALL" into the corresponding level (case-insensitive).static booleanwriteToFile(java.lang.String filename, java.lang.Object obj)Writes the given object to the specified file.static booleanwriteToFile(java.lang.String filename, java.lang.Object obj, boolean append)Writes the given object to the specified file.static booleanwriteToFile(java.lang.String filename, java.lang.String message)Writes the given message to the specified file.static booleanwriteToFile(java.lang.String filename, java.lang.String message, boolean append)Writes the given message to the specified file.
-
-
-
Field Detail
-
ALL
public static final java.util.logging.Level ALL
the log level All
-
CONFIG
public static final java.util.logging.Level CONFIG
the log level Vonfig
-
FINE
public static final java.util.logging.Level FINE
the log level Fine
-
FINER
public static final java.util.logging.Level FINER
the log level Finer
-
FINEST
public static final java.util.logging.Level FINEST
the log level Finest
-
INFO
public static final java.util.logging.Level INFO
the log level Info
-
OFF
public static final java.util.logging.Level OFF
the log level Off - i.e., no logging
-
SEVERE
public static final java.util.logging.Level SEVERE
the log level Severe
-
WARNING
public static final java.util.logging.Level WARNING
the log level Warning
-
-
Constructor Detail
-
Debug
public Debug()
default constructor, prints only to stdout
-
Debug
public Debug(java.lang.String filename)
logs the output to the specified file (and stdout). Size is 1,000,000 bytes and 1 file.- Parameters:
filename- the name of the log
-
Debug
public Debug(java.lang.String filename, int size, int numFiles)logs the output- Parameters:
filename- the name of the logsize- the size of the files in bytesnumFiles- the number of files for rotating
-
-
Method Detail
-
stringToLevel
public static java.util.logging.Level stringToLevel(java.lang.String level)
turns the string representing a level, e.g., "FINE" or "ALL" into the corresponding level (case-insensitive). The default is ALL.- Parameters:
level- the string to return a level for- Returns:
- the corresponding level or the default
-
newLog
public static Debug.Log newLog(java.lang.String filename, int size, int numFiles)
returns a new Log instance- Parameters:
filename- the name of the logsize- the size of the files in bytesnumFiles- the number of files for rotating- Returns:
- the log instance
-
log
public void log(java.lang.String message)
prints the given message with level INFO- Parameters:
message- the message to print
-
log
public void log(java.util.logging.Level level, java.lang.String message)prints the given message with the specified level and an empty sourceclass- Parameters:
level- the level of loggingmessage- the message to print
-
log
public void log(java.util.logging.Level level, java.lang.String sourceclass, java.lang.String message)prints the given message with the specified level- Parameters:
level- the level of loggingsourceclass- the class that logs the messagemessage- the message to print
-
log
public void log(java.util.logging.Level level, java.lang.String sourceclass, java.lang.String sourcemethod, java.lang.String message)prints the given message with the specified level- Parameters:
level- the level of loggingsourceclass- the class that logs the messagesourcemethod- the method that logs the messagemessage- the message to print
-
setEnabled
public void setEnabled(boolean value)
sets whether the logging is enabled or not- Parameters:
value- if true logging will be enabled
-
getEnabled
public boolean getEnabled()
returns whether the logging is enabled- Returns:
- true if the logging is enabled
-
newClock
public static Debug.Clock newClock()
returns a new instance of a clock- Returns:
- a new instance of a Clock
-
getClock
public Debug.Clock getClock()
returns the instance of the Clock that is internally used- Returns:
- the clock that's being used
-
startClock
public void startClock()
starts the clock
-
stopClock
public void stopClock(java.lang.String message)
stops the clock and prints the message associated with the time, but only if the logging is enabled.- Parameters:
message- the message to print- See Also:
getEnabled()
-
newRandom
public static java.util.Random newRandom()
returns a default debug random object, with no particular seed and debugging enabled.- Returns:
- a new instance of a Random object
-
newRandom
public static java.util.Random newRandom(int seed)
returns a debug random object with the specified seed and debugging enabled.- Parameters:
seed- the seed value- Returns:
- a new instance of a Random object
-
newTimestamp
public static Debug.Timestamp newTimestamp()
returns a default timestamp for the current date/time- Returns:
- a new timestamp
-
getTempDir
public static java.lang.String getTempDir()
returns the system temp directory- Returns:
- the temp directory
-
getHomeDir
public static java.lang.String getHomeDir()
returns the home directory of the user- Returns:
- the user's home directory
-
getCurrentDir
public static java.lang.String getCurrentDir()
returns the current working directory of the user- Returns:
- the user's current working directory
-
writeToFile
public static boolean writeToFile(java.lang.String filename, java.lang.Object obj)Writes the given object to the specified file. The string representation of the object is appended to the file.- Parameters:
filename- the file to write toobj- the object to write to the file- Returns:
- true if writing was successful
-
writeToFile
public static boolean writeToFile(java.lang.String filename, java.lang.String message)Writes the given message to the specified file. The message is appended to the file.- Parameters:
filename- the file to write tomessage- the message to write- Returns:
- true if writing was successful
-
writeToFile
public static boolean writeToFile(java.lang.String filename, java.lang.Object obj, boolean append)Writes the given object to the specified file. The string representation of the object is either appended or replaces the current content of the file.- Parameters:
filename- the file to write toobj- the object to write to the fileappend- whether to append the message or not- Returns:
- true if writing was successful
-
writeToFile
public static boolean writeToFile(java.lang.String filename, java.lang.String message, boolean append)Writes the given message to the specified file. The message is either appended or replaces the current content of the file.- Parameters:
filename- the file to write tomessage- the message to writeappend- whether to append the message or not- Returns:
- true if writing was successful
-
saveToFile
public static boolean saveToFile(java.lang.String filename, java.lang.Object o)writes the serialized object to the speicified file- Parameters:
filename- the file to serialize the object too- the object to serialize- Returns:
- true if writing was successful
-
loadFromFile
public static java.lang.Object loadFromFile(java.lang.String filename)
deserializes the content of the file and returns it, null if an error occurred.- Parameters:
filename- the name of the file to deserialize- Returns:
- the deserialized content, null if problem occurred
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Returns:
- the revision
-
-