Class TetradLogger
TetradLoggerConfig which will
be used to determine whether some event should be logged.
Although one can explicitly construct instance of TetradLoggerConfig and set them in the logger, the
configuration detail for most models is defined in the
configuration.xml file and added to the logger at startup. A pre-configured
TetradLoggerConfig for some model can be found by calling
getTetradLoggerConfigForModel(Class)
Furthermore, the logger supports logging to a sequence of files in some directory. To start logging to a new file in
the logging directory (assuming it has been set) call setNextOutputStream to remove this stream from the
logger call removeNextOutputStream. In adding to the feature arbitrary streams can be added and removed
from the logger by calling addOutputStream and
removeOutputStream.
- Version:
- $Id: $Id
- Author:
- Tyler Gibson
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents an empty configuration for the logger.static interfaceRepresents an output stream that can get its own length. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOutputStream(OutputStream stream) Sets theOutputStreamthat is used to log matters out to.voidaddTetradLoggerConfig(Class<?> model, TetradLoggerConfig config) Adds the givenTetradLoggerConfigto the logger, so that it can be used throughout the life of the application.voidAdds a TetradLoggerListener to the TetradLogger.voidclear()Removes all streams from the logger.voidLogs an error, this will log the message regardless of any configuration information.voidflush()Flushes the writers.voidforceLogMessage(String message) Logs the given message regardless of the logger's getModel settings.static TetradLoggerReturns an instance of TetradLogger.Getter for the fieldlatestFilePath.getLoggerForClass(Class<?> clazz) getLoggerForClass.getLoggingDirectory.getLoggingFilePrefix.booleanStates whether to display the log display.booleanStates whether file logging is enabled or not.booleanStates whether the logger is turned on or not.voidremoveNextOutputStream.voidremoveOutputStream(OutputStream stream) Removes the given stream from the logger.voidRemoves a TetradLoggerListener from the TetradLogger.voidreset()Resets the logger by removing any configuration info set withsetTetradLoggerConfig.voidsetAutomaticLogDisplayEnabled(boolean enable) States whether log displays should be automatically displayed or not.voidsetConfigForClass(Class<?> model) If there is a pre-defined configuration for the given model it is set, otherwise an exception is thrown.voidsetDisplayLogEnabled(boolean enabled) Sets whether the display log should be used or not.voidsetFileLoggingEnabled(boolean enabled) Sets whether "file logging" is enabled or not; that is whether calls tosetNextOutputStreamwill be respected.voidsetLogging(boolean logging) Sets whether the logger is on or not.voidsetLoggingDirectory(String directory) Sets the logging directory, but first checks whether we can write to it, etc.voidsetLoggingFilePrefix(String loggingFilePrefix) Sets the logging prefix.voidSets the next output stream to use it for logging, callremoveNextOutputStreamto remove it.voidSets what configuration should be used to determine which events to log.
-
Method Details
-
getInstance
Returns an instance of TetradLogger.- Returns:
- an instance of TetradLogger
-
addTetradLoggerListener
Adds a TetradLoggerListener to the TetradLogger. The listener will be notified whenever a logger configuration is set or reset.- Parameters:
l- the TetradLoggerListener to add
-
removeTetradLoggerListener
Removes a TetradLoggerListener from the TetradLogger.- Parameters:
l- the TetradLoggerListener to remove
-
setTetradLoggerConfig
Sets what configuration should be used to determine which events to log. Null can be given to remove a previously set configuration from the logger.- Parameters:
config- aTetradLoggerConfigobject
-
setConfigForClass
If there is a pre-defined configuration for the given model it is set, otherwise an exception is thrown.- Parameters:
model- aClassobject
-
addTetradLoggerConfig
Adds the givenTetradLoggerConfigto the logger, so that it can be used throughout the life of the application.- Parameters:
model- aClassobjectconfig- aTetradLoggerConfigobject
-
getLoggerForClass
getLoggerForClass.
- Parameters:
clazz- aClassobject- Returns:
- a
TetradLoggerConfigobject
-
reset
public void reset()Resets the logger by removing any configuration info set withsetTetradLoggerConfig. -
isLogging
public boolean isLogging()States whether the logger is turned on or not.- Returns:
- true iff the logger is logging.
-
setLogging
public void setLogging(boolean logging) Sets whether the logger is on or not.- Parameters:
logging- a boolean
-
flush
public void flush()Flushes the writers. -
error
Logs an error, this will log the message regardless of any configuration information. Although it won't be logged if the logger is off and if there are no streams attached.- Parameters:
message- aStringobject
-
forceLogMessage
Logs the given message regardless of the logger's getModel settings. Although nothing will be logged if the logger has been turned off.- Parameters:
message- aStringobject
-
addOutputStream
Sets theOutputStreamthat is used to log matters out to.- Parameters:
stream- aOutputStreamobject
-
removeOutputStream
Removes the given stream from the logger.- Parameters:
stream- aOutputStreamobject
-
clear
public void clear()Removes all streams from the logger. -
setNextOutputStream
public void setNextOutputStream()Sets the next output stream to use it for logging, callremoveNextOutputStreamto remove it. This will create the next output file in the output directory and form a stream from it and add it to the logger.- Throws:
IllegalStateException- - Thrown if there is an error setting the stream, the message will state the nature of the error.
-
removeNextOutputStream
public void removeNextOutputStream()removeNextOutputStream.
-
getLoggingFilePrefix
getLoggingFilePrefix.
- Returns:
- - prefix
-
setLoggingFilePrefix
Sets the logging prefix.- Parameters:
loggingFilePrefix- aStringobject
-
isDisplayLogEnabled
public boolean isDisplayLogEnabled()States whether to display the log display.- Returns:
- a boolean
-
setDisplayLogEnabled
public void setDisplayLogEnabled(boolean enabled) Sets whether the display log should be used or not.- Parameters:
enabled- a boolean
-
isFileLoggingEnabled
public boolean isFileLoggingEnabled()States whether file logging is enabled or not.- Returns:
- a boolean
-
setFileLoggingEnabled
public void setFileLoggingEnabled(boolean enabled) Sets whether "file logging" is enabled or not; that is whether calls tosetNextOutputStreamwill be respected.- Parameters:
enabled- a boolean
-
setAutomaticLogDisplayEnabled
public void setAutomaticLogDisplayEnabled(boolean enable) States whether log displays should be automatically displayed or not.- Parameters:
enable- a boolean
-
getLoggingDirectory
getLoggingDirectory.
- Returns:
- - logging directory.
-
setLoggingDirectory
Sets the logging directory, but first checks whether we can write to it, etc.- Parameters:
directory- - The directory to set.- Throws:
IllegalStateException- if there is a problem with the directory.
-
getLatestFilePath
Getter for the field
latestFilePath.- Returns:
- a
Stringobject
-