Interface LogManager
- All Known Implementing Classes:
BasicLogManager,ForwardingLogManager,LogManagerWithoutDuplicates,NullLogManager,TestLogManager
The log levels used are the ones from java.util.logging. SEVERE, WARNING and INFO are used normally, the first two denoting (among other things) exceptions. FINE, FINER, FINEST, and ALL correspond to main application, central algorithm, component level, and debug level respectively.
The main advantage of this interface is that the arguments to the log methods are only converted to strings, if the message is really logged.
-
Method Summary
Modifier and TypeMethodDescriptionstatic LogManagerReturn a LogManager that does not log anything.static LogManagerReturn a LogManager implementation intended for testing when nothing should actually be logged.voidflush()Flush all handlers of this logger.voidLogs any message occurring during program execution.voidLogs any message occurring during program execution.voidLog an exception solely for the purpose of debugging.voidlogDebugException(Throwable e, @Nullable String additionalMessage) Log an exception solely for the purpose of debugging.voidlogException(Level priority, Throwable e, @Nullable String additionalMessage) Log an exception by printing the full details to the user.voidLogs any message occurring during program execution.voidlogfDebugException(Throwable e, String format, Object... args) Log an exception solely for the purpose of debugging.voidlogfException(Level priority, Throwable e, String format, Object... args) Log an exception by printing the full details to the user.voidlogfUserException(Level priority, Throwable e, String format, Object... args) Log a message by printing its message to the user.voidlogUserException(Level priority, Throwable e, @Nullable String additionalMessage) Log a message by printing its message to the user.withComponentName(String name) Returns a new LogManager instance which may use the given name as an indicator from which component a log message comes from.booleanwouldBeLogged(Level priority) Returns true if a message with the given log level would be logged.
-
Method Details
-
withComponentName
Returns a new LogManager instance which may use the given name as an indicator from which component a log message comes from.- Parameters:
name- A non-empty string.- Returns:
- A LogManager instance.
-
wouldBeLogged
Returns true if a message with the given log level would be logged.- Parameters:
priority- the log level- Returns:
- whether this log level is enabled
-
log
Logs any message occurring during program execution. The message is constructed lazily by concatenating the parts with " ". The caller should not use string concatenation to create the message in order to increase performance if the message is never logged. To make individual arguments lazy, useMoreStrings.lazyString(Supplier).- Parameters:
priority- the log level for the messageargs- the parts of the message (can be an arbitrary number of objects whoseObject.toString()method is called)
-
log
Logs any message occurring during program execution. The message is constructed lazily by asking the provided supplier if necessary.- Parameters:
priority- the log level for the messagemsgSupplier- a supplier for a non-null log message
-
logf
Logs any message occurring during program execution. The message is constructed lazily fromString.format(format, args). To make individual arguments lazy, useMoreStrings.lazyString(Supplier).- Parameters:
priority- the log level for the messageformat- The format string.args- The arguments for the format string.
-
logUserException
Log a message by printing its message to the user. The details (e.g., stack trace) are hidden from the user and logged with a lower log level.Use this method in cases where an expected exception with a useful error message is thrown, e.g. an InvalidConfigurationException.
If you want to log an IOException because of a write error, it is recommended to write the message like "Could not write FOO to file". The final message will then be "Could not write FOO to file FOO.txt (REASON)".
- Parameters:
priority- the log level for the messagee- the occurred exceptionadditionalMessage- an optional message
-
logfUserException
Log a message by printing its message to the user. The details (e.g., stack trace) are hidden from the user and logged with a lower log level.Use this method in cases where an expected exception with a useful error message is thrown, e.g. an InvalidConfigurationException.
The message is constructed lazily from
String.format(format, args). To make individual arguments lazy, useMoreStrings.lazyString(Supplier).If you want to log an IOException because of a write error, it is recommended to write the message like "Could not write FOO to file". The final message will then be "Could not write FOO to file FOO.txt (REASON)".
- Parameters:
priority- the log level for the messagee- the occurred exceptionformat- The format string.args- The arguments for the format string.
-
logDebugException
Log an exception solely for the purpose of debugging. In default configuration, this exception is not shown to the user!Use this method when you want to log an exception that was handled by the catching site, but you don't want to forget the information completely.
- Parameters:
e- the occurred exceptionadditionalMessage- an optional message
-
logfDebugException
Log an exception solely for the purpose of debugging. In default configuration, this exception is not shown to the user!Use this method when you want to log an exception that was handled by the catching site, but you don't want to forget the information completely.
The message is constructed lazily from
String.format(format, args). To make individual arguments lazy, useMoreStrings.lazyString(Supplier).- Parameters:
e- the occurred exceptionformat- The format string.args- The arguments for the format string.
-
logDebugException
Log an exception solely for the purpose of debugging. In default configuration, this exception is not shown to the user!Use this method when you want to log an exception that was handled by the catching site, but you don't want to forget the information completely.
- Parameters:
e- the occurred exception
-
logException
Log an exception by printing the full details to the user.This method should only be used in cases where logUserException and logDebugException are not acceptable.
- Parameters:
priority- the log level for the messagee- the occurred exceptionadditionalMessage- an optional message
-
logfException
Log an exception by printing the full details to the user.This method should only be used in cases where logUserException and logDebugException are not acceptable.
The message is constructed lazily from
String.format(format, args). To make individual arguments lazy, useMoreStrings.lazyString(Supplier).- Parameters:
priority- the log level for the messagee- the occurred exceptionformat- The format string.args- The arguments for the format string.
-
flush
void flush()Flush all handlers of this logger. -
createNullLogManager
Return a LogManager that does not log anything.Note: Do not use this implementation for unit tests, use
createTestLogManager()instead. -
createTestLogManager
Return a LogManager implementation intended for testing when nothing should actually be logged.Compared to
createTestLogManager(), it does check all the parameters for validity, i.e. non-nullness and correct string format.
-