Class SimLogger

java.lang.Object
nl.tudelft.simulation.dsol.logger.SimLogger

public class SimLogger extends Object
SimLogger implements a logger with functionality of the CategoryLogger, but the logger is simulator-aware and can print the simulator time as part of the log message. Because multiple simulators can run in parallel, the SimLogger class is specific for each instantiated Simulator.

Copyright (c) 2018 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://https://simulation.tudelft.nl/dsol/docs/latest/license.html.

Author:
Alexander Verbraeck
  • Field Details

    • NO_LOGGER

      public static final CategoryLogger.DelegateLogger NO_LOGGER
      The delegate logger that returns immediately after a negative filter outcome.
  • Constructor Details

    • SimLogger

      public SimLogger(SimulatorInterface<?> simulator)
      Construct a simulator-specific logger.
      Parameters:
      simulator - SimulatorInterface<?, ?, ?>; the simulator to which this logger belongs
  • Method Details

    • setSimTimeFormatter

      public void setSimTimeFormatter(SimTimeFormatter simTimeFormatter)
      Set the formatter to include the simulator time in the log messages.
      Parameters:
      simTimeFormatter - SimTimeFormatter; the new formatter
    • setAllLogMessageFormat

      public void setAllLogMessageFormat(String newMessageFormat)
      Set a new logging format for the message lines of all writers. The default message format is:
      {class_name}.{method}:{line} {message|indent=4}

      A few popular placeholders that can be used:
      - {class} Fully-qualified class name where the logging request is issued
      - {class_name} Class name (without package) where the logging request is issued
      - {date} Date and time of the logging request, e.g. {date:yyyy-MM-dd HH:mm:ss} [SimpleDateFormat]
      - {level} Logging level of the created log entry
      - {line} Line number from where the logging request is issued
      - {message} Associated message of the created log entry
      - {method} Method name from where the logging request is issued
      - {package} Package where the logging request is issued
      Parameters:
      newMessageFormat - String; the new formatting pattern to use for all registered writers
      See Also:
    • setAllLogLevel

      public void setAllLogLevel(Level newLevel)
      Set a new logging level for all registered writers.
      Parameters:
      newLevel - Level; the new log level for all registered writers
    • setLogMessageFormat

      public void setLogMessageFormat(Writer writer, String newMessageFormat)
      Set a new logging format for the message lines of a writer. The default message format is:
      {class_name}.{method}:{line} {message|indent=4}

      A few popular placeholders that can be used:
      - {class} Fully-qualified class name where the logging request is issued
      - {class_name} Class name (without package) where the logging request is issued
      - {date} Date and time of the logging request, e.g. {date:yyyy-MM-dd HH:mm:ss} [SimpleDateFormat]
      - {level} Logging level of the created log entry
      - {line} Line number from where the logging request is issued
      - {message} Associated message of the created log entry
      - {method} Method name from where the logging request is issued
      - {package} Package where the logging request is issued
      Parameters:
      writer - Writer; the writer to change the mesage format for
      newMessageFormat - String; the new formatting pattern to use for all registered writers
      See Also:
    • setLogLevel

      public void setLogLevel(Writer writer, Level newLevel)
      Set a new logging level for one of the registered writers.
      Parameters:
      writer - Writer; the writer to change the log level for
      newLevel - Level; the new log level for the writer
    • addLogCategory

      public void addLogCategory(LogCategory logCategory)
      Add a category to be logged to the Writers.
      Parameters:
      logCategory - LogCategory; the LogCategory to add
    • removeLogCategory

      public void removeLogCategory(LogCategory logCategory)
      Remove a category to be logged to the Writers.
      Parameters:
      logCategory - LogCategory; the LogCategory to remove
    • setLogCategories

      public void setLogCategories(LogCategory... newLogCategories)
      Set the categories to be logged to the Writers.
      Parameters:
      newLogCategories - LogCategory...; the LogCategories to set, replacing the previous ones
    • always

      The "pass" filter that will result in always trying to log.
      Returns:
      the logger that tries to execute logging (delegateLogger)
    • filter

      public CategoryLogger.DelegateLogger filter(LogCategory logCategory)
      Check whether the provided category needs to be logged. Note that when LogCategory.ALL is contained in the categories, filter will return true.
      Parameters:
      logCategory - LogCategory; the category to check for.
      Returns:
      the logger that either tries to log (delegateLogger), or returns without logging (noLogger)
    • filter

      public CategoryLogger.DelegateLogger filter(LogCategory... filterCategories)
      Check whether the provided categories contain one or more categories that need to be logged. Note that when LogCategory.ALL is contained in the categories, filter will return true.
      Parameters:
      filterCategories - LogCategory...; elements or array with the categories to check for
      Returns:
      the logger that either tries to log (delegateLogger), or returns without logging (noLogger)
    • filter

      public CategoryLogger.DelegateLogger filter(Set<LogCategory> filterCategories)
      Check whether the provided categories contain one or more categories that need to be logged. Note that when LogCategory.ALL is contained in the categories, filter will return true.
      Parameters:
      filterCategories - Set<LogCategory>; the categories to check for
      Returns:
      the logger that either tries to log (delegateLogger), or returns without logging (noLogger)