Class BasicLogManager
- java.lang.Object
-
- org.sosy_lab.common.log.BasicLogManager
-
- All Implemented Interfaces:
AutoCloseable
,LogManager
public class BasicLogManager extends Object implements LogManager, AutoCloseable
Default implementation ofLogManager
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
BasicLogManager.LogManagerMXBean
-
Constructor Summary
Constructors Constructor Description BasicLogManager(Logger pLogger)
Constructor which allows to customize where this logger delegates to.BasicLogManager(Logger pLogger, int pTruncateSize)
Constructor which allows to customize where this logger delegates to.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
static LogManager
create(Configuration config)
Create aBasicLogManager
which logs to a file and the console according to user configuration.static LogManager
create(LoggingOptions options)
Create aBasicLogManager
which logs to a file and the console according to specified options.static LogManager
createWithHandler(Handler handler)
Create aBasicLogManager
which delegates to a new logger with only the givenHandler
.void
flush()
Flush all handlers of this logger.void
log(Level priority, Object... args)
Logs any message occurring during program execution.void
log(Level priority, Supplier<String> msgSupplier)
Logs any message occurring during program execution.void
logDebugException(Throwable e)
Log an exception solely for the purpose of debugging.void
logDebugException(Throwable pE, @Nullable String pAdditionalMessage)
Log an exception solely for the purpose of debugging.void
logException(Level pPriority, Throwable pE, @Nullable String pAdditionalMessage)
Log an exception by printing the full details to the user.void
logf(Level priority, String format, Object... args)
Logs any message occurring during program execution.void
logfDebugException(Throwable e, String format, Object... args)
Log an exception solely for the purpose of debugging.void
logfException(Level priority, Throwable e, String format, Object... args)
Log an exception by printing the full details to the user.void
logfUserException(Level priority, Throwable e, String format, Object... args)
Log a message by printing its message to the user.void
logUserException(Level priority, Throwable e, @Nullable String pAdditionalMessage)
Log a message by printing its message to the user.LogManager
withComponentName(String pName)
Returns a new LogManager instance which may use the given name as an indicator from which component a log message comes from.boolean
wouldBeLogged(Level priority)
Returns true if a message with the given log level would be logged.
-
-
-
Constructor Detail
-
BasicLogManager
public BasicLogManager(Logger pLogger)
Constructor which allows to customize where this logger delegates to.The feature of truncating long log messages is disabled.
- Parameters:
pLogger
- The Java logger where this logger delegates to.
-
BasicLogManager
public BasicLogManager(Logger pLogger, int pTruncateSize)
Constructor which allows to customize where this logger delegates to.- Parameters:
pLogger
- The Java logger where this logger delegates to.pTruncateSize
- A positive integer threshold for truncating long log messages, or 0 to disable truncation.
-
-
Method Detail
-
createWithHandler
public static LogManager createWithHandler(Handler handler)
Create aBasicLogManager
which delegates to a new logger with only the givenHandler
.- Parameters:
handler
- The target handler.
-
create
public static LogManager create(Configuration config) throws InvalidConfigurationException
Create aBasicLogManager
which logs to a file and the console according to user configuration.This also adds an MXBean that allows runtime control of some logging options.
- Throws:
InvalidConfigurationException
-
create
public static LogManager create(LoggingOptions options)
Create aBasicLogManager
which logs to a file and the console according to specified options.This also adds an MXBean that allows runtime control of some logging options.
Most users will want to use
create(Configuration)
instead.
-
withComponentName
public LogManager withComponentName(String pName)
Description copied from interface:LogManager
Returns a new LogManager instance which may use the given name as an indicator from which component a log message comes from.- Specified by:
withComponentName
in interfaceLogManager
- Parameters:
pName
- A non-empty string.- Returns:
- A LogManager instance.
-
wouldBeLogged
public boolean wouldBeLogged(Level priority)
Returns true if a message with the given log level would be logged.- Specified by:
wouldBeLogged
in interfaceLogManager
- Parameters:
priority
- the log level- Returns:
- whether this log level is enabled
-
log
public void log(Level priority, Object... args)
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.- Specified by:
log
in interfaceLogManager
- 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
public void log(Level priority, Supplier<String> msgSupplier)
Description copied from interface:LogManager
Logs any message occurring during program execution. The message is constructed lazily by asking the provided supplier if necessary.- Specified by:
log
in interfaceLogManager
- Parameters:
priority
- the log level for the messagemsgSupplier
- a supplier for a non-null log message
-
logf
public void logf(Level priority, String format, Object... args)
Logs any message occurring during program execution. The message is constructed lazily fromString.format(format, args)
.- Specified by:
logf
in interfaceLogManager
- Parameters:
priority
- the log level for the messageformat
- The format string.args
- The arguments for the format string.
-
logUserException
public void logUserException(Level priority, Throwable e, @Nullable String pAdditionalMessage)
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)".
- Specified by:
logUserException
in interfaceLogManager
- Parameters:
priority
- the log level for the messagee
- the occurred exceptionpAdditionalMessage
- an optional message
-
logfUserException
public void logfUserException(Level priority, Throwable e, String format, Object... args)
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)".
- Specified by:
logfUserException
in interfaceLogManager
- Parameters:
priority
- the log level for the messagee
- the occurred exceptionformat
- The format string.args
- The arguments for the format string.
-
logDebugException
public void logDebugException(Throwable pE, @Nullable String pAdditionalMessage)
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.
- Specified by:
logDebugException
in interfaceLogManager
- Parameters:
pE
- the occurred exceptionpAdditionalMessage
- an optional message
-
logDebugException
public void logDebugException(Throwable e)
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.
- Specified by:
logDebugException
in interfaceLogManager
- Parameters:
e
- the occurred exception
-
logfDebugException
public void logfDebugException(Throwable e, String format, Object... args)
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)
.- Specified by:
logfDebugException
in interfaceLogManager
- Parameters:
e
- the occurred exceptionformat
- The format string.args
- The arguments for the format string.
-
logException
public void logException(Level pPriority, Throwable pE, @Nullable String pAdditionalMessage)
Description copied from interface:LogManager
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.
- Specified by:
logException
in interfaceLogManager
- Parameters:
pPriority
- the log level for the messagepE
- the occurred exceptionpAdditionalMessage
- an optional message
-
logfException
public void logfException(Level priority, Throwable e, String format, Object... args)
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)
.- Specified by:
logfException
in interfaceLogManager
- Parameters:
priority
- the log level for the messagee
- the occurred exceptionformat
- The format string.args
- The arguments for the format string.
-
flush
public void flush()
Description copied from interface:LogManager
Flush all handlers of this logger.- Specified by:
flush
in interfaceLogManager
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
-