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 class
Represents an empty configuration for the logger.static interface
Represents an output stream that can get its own length. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addOutputStream
(OutputStream stream) Sets theOutputStream
that is used to log matters out to.void
addTetradLoggerConfig
(Class<?> model, TetradLoggerConfig config) Adds the givenTetradLoggerConfig
to the logger, so that it can be used throughout the life of the application.void
Adds a TetradLoggerListener to the TetradLogger.void
clear()
Removes all streams from the logger.void
Logs an error, this will log the message regardless of any configuration information.void
flush()
Flushes the writers.static TetradLogger
Returns an instance of TetradLogger.Getter for the fieldlatestFilePath
.getLoggerForClass
(Class<?> clazz) getLoggerForClass.getLoggingDirectory.getLoggingFilePrefix.boolean
States whether to display the log display.boolean
States whether file logging is enabled or not.boolean
States whether the logger is turned on or not.void
Logs the given message regardless of the logger's getModel settings.void
removeNextOutputStream.void
removeOutputStream
(OutputStream stream) Removes the given stream from the logger.void
Removes a TetradLoggerListener from the TetradLogger.void
reset()
Resets the logger by removing any configuration info set withsetTetradLoggerConfig
.void
setAutomaticLogDisplayEnabled
(boolean enable) States whether log displays should be automatically displayed or not.void
setConfigForClass
(Class<?> model) If there is a pre-defined configuration for the given model it is set, otherwise an exception is thrown.void
setDisplayLogEnabled
(boolean enabled) Sets whether the display log should be used or not.void
setFileLoggingEnabled
(boolean enabled) Sets whether "file logging" is enabled or not; that is whether calls tosetNextOutputStream
will be respected.void
setLogging
(boolean logging) Sets whether the logger is on or not.void
setLoggingDirectory
(String directory) Sets the logging directory, but first checks whether we can write to it, etc.void
setLoggingFilePrefix
(String loggingFilePrefix) Sets the logging prefix.void
Sets the next output stream to use it for logging, callremoveNextOutputStream
to remove it.void
Sets 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
- aTetradLoggerConfig
object
-
setConfigForClass
-
addTetradLoggerConfig
Adds the givenTetradLoggerConfig
to the logger, so that it can be used throughout the life of the application.- Parameters:
model
- aClass
objectconfig
- aTetradLoggerConfig
object
-
getLoggerForClass
getLoggerForClass.
- Parameters:
clazz
- aClass
object- Returns:
- a
TetradLoggerConfig
object
-
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
-
log
-
addOutputStream
Sets theOutputStream
that is used to log matters out to.- Parameters:
stream
- aOutputStream
object
-
removeOutputStream
Removes the given stream from the logger.- Parameters:
stream
- aOutputStream
object
-
clear
public void clear()Removes all streams from the logger. -
setNextOutputStream
public void setNextOutputStream()Sets the next output stream to use it for logging, callremoveNextOutputStream
to 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
-
setLoggingFilePrefix
-
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 tosetNextOutputStream
will 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
-
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
-