Class Logger

java.lang.Object
org.opentrafficsim.base.logger.Logger

public final class Logger extends Object
Logger for within OTS context. This logger uses category OTS and a format that may include simulation time, PID and thread id. Every simulator in OTS can attach itself as simulation time supplier through Logger.setSimtimeSupplier(). The time supplier only applies to the Thread that creates it, and all threads created downstream of this thread. This means that when different simulations run within a single JVM, each log line will report the time of the relevant simulation. This does require that the simulator (or animator) is created in a dedicated thread for the parallel simulation. Example usage:
 Logger.ots().trace("Logging example");
 

Copyright (c) 2025-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Wouter Schakel
  • Field Details

    • OTS

      public static final LogCategory OTS
      Default OTS log category.
  • Method Details

    • ots

      public static CategoryLogger.DelegateLogger ots()
      Returns logger with the OTS category.
      Returns:
      logger with the OTS category
    • setLogLevel

      public static void setLogLevel(ch.qos.logback.classic.Level level)
      Set log level of the OTS logger.
      Parameters:
      level - log level
    • setSimTimeSupplier

      public static void setSimTimeSupplier(Supplier<? extends Number> timeSupplier)
      Sets supplier of the simulation time. The value is formatted with [%8.3fs]. The time supplier only applies to the Thread that creates it, and all threads created downstream of this thread.
      Parameters:
      timeSupplier - supplier of the simulation time
    • setSimTimeSupplier

      public static void setSimTimeSupplier(Supplier<? extends Number> timeSupplier, String timeFormat)
      Sets supplier of the simulation time with dedicated format string. If the format string does not start with a blank, a blank is added at the beginning of the format string. The time supplier only applies to the Thread that creates it, and all threads created downstream of this thread.
      Parameters:
      timeSupplier - supplier of the simulation time
      timeFormat - format string for the time value
    • removeSimTimeSupplier

      public static void removeSimTimeSupplier(Supplier<? extends Number> timeSupplier)
      Removes the supplier of the simulation time, but only if it is the same as the input argument.
      Parameters:
      timeSupplier - supplier of the simulation time
    • includePid

      public static void includePid(boolean include)
      Sets the PID to be included in formatting or not. The default format is "pid=%d". To provide a format string use includePid(String).
      Parameters:
      include - whether to include the PID in formatting
    • includePid

      public static void includePid(String format)
      Sets the PID to be included in formatting with the given format.
      Parameters:
      format - format for PID
    • includeThreadId

      public static void includeThreadId(boolean include)
      Sets the thread id to be included in formatting or not. The default format is "thread=%d". To provide a format string use includeThreadId(String).
      Parameters:
      include - whether to include the thread id in formatting
    • includeThreadId

      public static void includeThreadId(String format)
      Sets the PID to be included in formatting with the given format.
      Parameters:
      format - format for PID