Package org.opentrafficsim.base.logger
Class Logger
java.lang.Object
org.opentrafficsim.base.logger.Logger
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidincludePid(boolean include) Sets the PID to be included in formatting or not.static voidincludePid(String format) Sets the PID to be included in formatting with the given format.static voidincludeThreadId(boolean include) Sets the thread id to be included in formatting or not.static voidincludeThreadId(String format) Sets the PID to be included in formatting with the given format.ots()Returns logger with the OTS category.static voidremoveSimTimeSupplier(Supplier<? extends Number> timeSupplier) Removes the supplier of the simulation time, but only if it is the same as the input argument.static voidsetLogLevel(ch.qos.logback.classic.Level level) Set log level of the OTS logger.static voidsetSimTimeSupplier(Supplier<? extends Number> timeSupplier) Sets supplier of the simulation time.static voidsetSimTimeSupplier(Supplier<? extends Number> timeSupplier, String timeFormat) Sets supplier of the simulation time with dedicated format string.
-
Field Details
-
OTS
Default OTS log category.
-
-
Method Details
-
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
Sets supplier of the simulation time. The value is formatted with[%8.3fs]. The time supplier only applies to theThreadthat creates it, and all threads created downstream of this thread.- Parameters:
timeSupplier- supplier of the simulation time
-
setSimTimeSupplier
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 theThreadthat creates it, and all threads created downstream of this thread.- Parameters:
timeSupplier- supplier of the simulation timetimeFormat- format string for the time value
-
removeSimTimeSupplier
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 useincludePid(String).- Parameters:
include- whether to include the PID in formatting
-
includePid
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 useincludeThreadId(String).- Parameters:
include- whether to include the thread id in formatting
-
includeThreadId
Sets the PID to be included in formatting with the given format.- Parameters:
format- format for PID
-