Class SimLogger
java.lang.Object
nl.tudelft.simulation.dsol.logger.SimLogger
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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
DelegateSimLogger class that takes care of actually logging the message and/or exception. -
Field Summary
Modifier and TypeFieldDescriptionstatic final CategoryLogger.DelegateLogger
The delegate logger that returns immediately after a negative filter outcome. -
Constructor Summary
ConstructorDescriptionSimLogger
(SimulatorInterface<?> simulator) Construct a simulator-specific logger. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addLogCategory
(LogCategory logCategory) Add a category to be logged to the Writers.always()
The "pass" filter that will result in always trying to log.filter
(Set<LogCategory> filterCategories) Check whether the provided categories contain one or more categories that need to be logged.filter
(LogCategory logCategory) Check whether the provided category needs to be logged.filter
(LogCategory... filterCategories) Check whether the provided categories contain one or more categories that need to be logged.void
removeLogCategory
(LogCategory logCategory) Remove a category to be logged to the Writers.void
setAllLogLevel
(Level newLevel) Set a new logging level for all registered writers.void
setAllLogMessageFormat
(String newMessageFormat) Set a new logging format for the message lines of all writers.void
setLogCategories
(LogCategory... newLogCategories) Set the categories to be logged to the Writers.void
setLogLevel
(Writer writer, Level newLevel) Set a new logging level for one of the registered writers.void
setLogMessageFormat
(Writer writer, String newMessageFormat) Set a new logging format for the message lines of a writer.void
setSimTimeFormatter
(SimTimeFormatter simTimeFormatter) Set the formatter to include the simulator time in the log messages.
-
Field Details
-
NO_LOGGER
The delegate logger that returns immediately after a negative filter outcome.
-
-
Constructor Details
-
SimLogger
Construct a simulator-specific logger.- Parameters:
simulator
- SimulatorInterface<?, ?, ?>; the simulator to which this logger belongs
-
-
Method Details
-
setSimTimeFormatter
Set the formatter to include the simulator time in the log messages.- Parameters:
simTimeFormatter
- SimTimeFormatter; the new formatter
-
setAllLogMessageFormat
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
Set a new logging level for all registered writers.- Parameters:
newLevel
- Level; the new log level for all registered writers
-
setLogMessageFormat
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 fornewMessageFormat
- String; the new formatting pattern to use for all registered writers- See Also:
-
setLogLevel
Set a new logging level for one of the registered writers.- Parameters:
writer
- Writer; the writer to change the log level fornewLevel
- Level; the new log level for the writer
-
addLogCategory
Add a category to be logged to the Writers.- Parameters:
logCategory
- LogCategory; the LogCategory to add
-
removeLogCategory
Remove a category to be logged to the Writers.- Parameters:
logCategory
- LogCategory; the LogCategory to remove
-
setLogCategories
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
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
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
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)
-