Class LoggingExtension

java.lang.Object
org.moeaframework.algorithm.extension.LoggingExtension
All Implemented Interfaces:
Extension

public class LoggingExtension extends Object implements Extension
Extension that logs information about the execution, including the current NFE and elapsed time. Furthermore, the static methods can be used to write log messages if the algorithm has logging enabled.
  • Field Details

    • DEFAULT_LOG_FREQUENCY

      public static final Duration DEFAULT_LOG_FREQUENCY
      The default logging frequency for status messages.
  • Constructor Details

    • LoggingExtension

      public LoggingExtension()
      Constructs a new, default logging extension.
    • LoggingExtension

      public LoggingExtension(String name)
      Constructs a new logger with the given name.
      Parameters:
      name - the logger name
    • LoggingExtension

      public LoggingExtension(String name, Duration logFrequency)
      Constructs a new logger with the given name and settings.
      Parameters:
      name - the logger name
      logFrequency - the frequency to print log messages
    • LoggingExtension

      public LoggingExtension(Logger logger, Duration logFrequency)
      Constructs a new logger with the given name and settings.
      Parameters:
      logger - the logger
      logFrequency - the frequency to print log messages
      frequencyType - the type of frequency
  • Method Details

    • onStep

      public void onStep(Algorithm algorithm)
      Description copied from interface: Extension
      Called after each step of the algorithm.
      Specified by:
      onStep in interface Extension
      Parameters:
      algorithm - the algorithm associated with this extension
    • onRegister

      public void onRegister(Algorithm algorithm)
      Description copied from interface: Extension
      Called when this extension is registered with an algorithm. This can be used to perform any type checking or initialization.
      Specified by:
      onRegister in interface Extension
      Parameters:
      algorithm - the algorithm associated with this extension
    • onTerminate

      public void onTerminate(Algorithm algorithm)
      Description copied from interface: Extension
      Called after the termination of an algorithm.
      Specified by:
      onTerminate in interface Extension
      Parameters:
      algorithm - the algorithm associated with this extension
    • getLogger

      public Logger getLogger()
      Returns the logger used by this extension.
      Returns:
      the logger
    • log

      public void log(Level level, String message, Object... params)
      Writes a log message using this extension.
      Parameters:
      level - the log level
      message - the log message
      params - additional parameters used to format the log message
    • info

      public static void info(Algorithm algorithm, String message, Object... params)
      Writes an informational (Level.INFO) log message if the algorithm has logging enabled.
      Parameters:
      algorithm - the algorithm
      message - the log message
      params - additional parameters used to format the log message
    • warning

      public static void warning(Algorithm algorithm, String message, Object... params)
      Writes a warning (Level.WARNING) log message if the algorithm has logging enabled.
      Parameters:
      algorithm - the algorithm
      message - the log message
      params - additional parameters used to format the log message
    • severe

      public static void severe(Algorithm algorithm, String message, Object... params)
      Writes a severe (Level.SEVERE) log message if the algorithm has logging enabled.
      Parameters:
      algorithm - the algorithm
      message - the log message
      params - additional parameters used to format the log message
    • log

      public static void log(Algorithm algorithm, Level level, String message, Object... params)
      Writes a log message if the algorithm has logging enabled.
      Parameters:
      algorithm - the algorithm
      level - the log level
      message - the log message
      params - additional parameters used to format the log message