Class TetradLogger

java.lang.Object
edu.cmu.tetrad.util.TetradLogger

public class TetradLogger extends Object
Represents a logging utility used throughout tetrad. Unlike a typical logger this does not work on levels, instead one can set events need to be logged. This is done by giving the logger a TetradLoggerConfig which will be used to determine whether some event should be logged.

Although one can explicity construct instance of TetradLoggerConfig and set them in the logger, the configuration details 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 addiong to the feature arbitrary streams can be add and removed from the logger by calling addOutputStream and removeOutputStream.

Author:
Tyler Gibson
  • Method Details

    • getInstance

      public static TetradLogger getInstance()
      Returns:
      - instance
    • addTetradLoggerListener

      public void addTetradLoggerListener(TetradLoggerListener l)
      Adds the given listener to the logger.
    • removeTetradLoggerListener

      public void removeTetradLoggerListener(TetradLoggerListener l)
      Removes the given listener from the logger.
    • setTetradLoggerConfig

      public void setTetradLoggerConfig(TetradLoggerConfig config)
      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.
    • setEventsToLog

      public void setEventsToLog(String... events)
      This can be used to tell the logger which events to log without having to first define a TetradLoggerConfig.
    • setForceLog

      public void setForceLog(boolean force)
      Forces the logger to log all events, useful for testing.
    • setConfigForClass

      public void setConfigForClass(Class model)
      If there is a pre-defined configuration for the given model it is set, otherwise an exception is thrown.
    • addTetradLoggerConfig

      public void addTetradLoggerConfig(Class model, TetradLoggerConfig config)
      Adds the given TetradLoggerConfig to the logger, so that it can be used throughout the life of the application.
    • getLoggerForClass

      public TetradLoggerConfig getLoggerForClass(Class clazz)
    • reset

      public void reset()
      Resets the logger by removing any configuration info set with setTetradLoggerConfig.
    • 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.
    • flush

      public void flush()
      Flushes the writers.
    • log

      public void log(String event, String message)
      Logs the given message with a newline associated with the given event.
      Parameters:
      event - - The name of the log event.
      message - - The messag eto be logged.
    • error

      public void error(String message)
      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 of course if there are no streams attached.
    • forceLogMessage

      public void forceLogMessage(String message)
      Logs the given message regardless of the logger's getModel settings. Although nothing will be logged if the logger has been turned off.
    • addOutputStream

      public void addOutputStream(OutputStream stream)
      Sets the OutputStream that is used to log matters out to.
    • removeOutputStream

      public void removeOutputStream(OutputStream stream)
      Removes the given stream from the logger.
    • clear

      public void clear()
      Removes all streams from the logger.
    • setNextOutputStream

      public void setNextOutputStream()
      Sets the next output stream to use for logging, call removeNextOutputStream 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()
    • getLoggingFilePrefix

      public String getLoggingFilePrefix()
      Returns:
      - prefix
    • setLoggingFilePrefix

      public void setLoggingFilePrefix(String loggingFilePrefix)
      Sets the logging prefix.
    • isDisplayLogEnabled

      public boolean isDisplayLogEnabled()
      States whether to display the log display.
    • setDisplayLogEnabled

      public void setDisplayLogEnabled(boolean enabled)
      Sets whether the display log should be used or not.
    • isFileLoggingEnabled

      public boolean isFileLoggingEnabled()
      States whether file logging is enabled or not.
    • setFileLoggingEnabled

      public void setFileLoggingEnabled(boolean enabled)
      Sets whether "file logging" is enabled or not, that is whether calls to setNextOutputStream will be respected.
    • isAutomaticLogDisplayEnabled

      public Boolean isAutomaticLogDisplayEnabled()
      States whether the automatic log display is enabled or not, or returns null if there is no value stored in the user's prefs.
    • setAutomaticLogDisplayEnabled

      public void setAutomaticLogDisplayEnabled(boolean enable)
      States whether log displays should be automatically displayed or not.
    • getLoggingDirectory

      public String getLoggingDirectory()
      Returns:
      - logging directory.
    • setLoggingDirectory

      public void setLoggingDirectory(String directory)
      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.
    • isEventActive

      public boolean isEventActive(String id)
      States whether the given event is active or not.
    • getLatestFilePath

      public String getLatestFilePath()
    • getLoggerConfig

      public TetradLoggerConfig getLoggerConfig()