Interface ILoggingTool
- All Known Implementing Classes:
SystemOutLoggingTool
LoggingToolFactory.createLoggingTool(Class):
public class SomeClass {
private static ILoggingTool logger = LoggingToolFactory.createLoggingTool(SomeClass.class);
}
The logger has six logging levels:
- TRACE
- Emits the largest number of log entries.
- DEBUG
- Default mode. Used for information you might need to track down the cause of a bug in the source code, or to understand how an algorithm works.
- INFO
- For reporting informative information to the user that he might easily disregard. Real important information should be given to the user using a GUI element.
- WARNING
- This indicates a special situation which is unlike to happen, but for which no special actions need to be taken. E.g. missing information in files, or an unknown atom type. The action is normally something user friendly.
- ERROR
- This level is used for situations that should not have happened *and* thus indicate a bug.
- FATAL
- This level is used for situations that should not have happened *and* that lead to a situation where this program can no longer function (rare in Java).
Logging library might implement less logging levels than the six levels defined here. This may result in logging levels being merged. For example, slf4j has five logging levels. Logging level fatal is not supported so that calls to error and fatal are both logged with slf4j logging level error.
Consider that debugging will not always be turned on. Therefore, it is better not to concatenate string in the logger.debug() call, but have the ILoggingTool do this when appropriate. In other words, use:
logger.debug("The String X has this value: ", someString);
logger.debug("The int Y has this value: ", y);
instead of:
logger.debug("The String X has this value: " + someString);
logger.debug("The int Y has this value: " + y);
For logging calls that require even more computation you can use the
isDebugEnabled() method:
if (logger.isDebugEnabled()) {
logger.info("The 1056389822th prime that is used is: ",
calculatePrime(1056389822));
}
In addition to the methods specific in the interface, implementations
must also implement the static method create(Class<?>) which
is called by LoggingToolFactory to instantiate the
implementation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDebug, Info, Warn, Error, and Fatal messages will be emitted.static final intDefault number of StackTraceElements to be printed by debug(Exception).static final intError, and Fatal messages will be emitted.static final intOnly Fatal messages will be emitted.static final intInfo, Warn, Error, and Fatal messages will be emitted.static final intLogging is OFFstatic final intTrace, Debug, Info, Warn, Error, and Fatal messages will be emitted.static final intWarn, Error, and Fatal messages will be emitted. -
Method Summary
Modifier and TypeMethodDescriptionvoidShows DEBUG output for the Object.voidShows DEBUG output for the given Object's.voidOutputs the system property for java.class.path.voidOutputs system properties for the operating system and the java version.voidShows ERROR output for the Object.voidShows ERROR output for the given Object's.voidShows FATAL output for the Object.intgetLevel()Get the current level of this logger.voidShows INFO output for the Object.voidShows INFO output for the given Object's.booleanUse this method for computational demanding debug info.voidsetLevel(int level) Set the level of this logger.voidsetStackLength(int length) Sets the number of StackTraceElements to be printed in DEBUG mode when callingdebug(Throwable).voidShows WARN output for the Object.voidShows WARN output for the given Object's.
-
Field Details
-
TRACE
static final int TRACETrace, Debug, Info, Warn, Error, and Fatal messages will be emitted.- See Also:
-
DEBUG
static final int DEBUGDebug, Info, Warn, Error, and Fatal messages will be emitted.- See Also:
-
INFO
static final int INFOInfo, Warn, Error, and Fatal messages will be emitted.- See Also:
-
WARN
static final int WARNWarn, Error, and Fatal messages will be emitted.- See Also:
-
ERROR
static final int ERRORError, and Fatal messages will be emitted.- See Also:
-
FATAL
static final int FATALOnly Fatal messages will be emitted.- See Also:
-
OFF
static final int OFFLogging is OFF- See Also:
-
DEFAULT_STACK_LENGTH
static final int DEFAULT_STACK_LENGTHDefault number of StackTraceElements to be printed by debug(Exception).- See Also:
-
-
Method Details
-
dumpSystemProperties
void dumpSystemProperties()Outputs system properties for the operating system and the java version. More specifically: os.name, os.version, os.arch, java.version and java.vendor. -
setStackLength
void setStackLength(int length) Sets the number of StackTraceElements to be printed in DEBUG mode when callingdebug(Throwable). The default value is DEFAULT_STACK_LENGTH.- Parameters:
length- the new stack length- See Also:
-
dumpClasspath
void dumpClasspath()Outputs the system property for java.class.path. -
debug
Shows DEBUG output for the Object. If the object is an instanceofThrowableit will output the trace. Otherwise it will use the toString() method.- Parameters:
object- Object to apply toString() to and output
-
debug
Shows DEBUG output for the given Object's. It uses the toString() method to concatenate the objects.- Parameters:
object- Object to apply toString() to and outputobjects- Object... to apply toString() to and output
-
error
Shows ERROR output for the Object. It uses the toString() method.- Parameters:
object- Object to apply toString() to and output
-
error
Shows ERROR output for the given Object's. It uses the toString() method to concatenate the objects.- Parameters:
object- Object to apply toString() to and outputobjects- Object... to apply toString() to and output
-
fatal
Shows FATAL output for the Object. It uses the toString() method.- Parameters:
object- Object to apply toString() to and output
-
info
Shows INFO output for the Object. It uses the toString() method.- Parameters:
object- Object to apply toString() to and output
-
info
Shows INFO output for the given Object's. It uses the toString() method to concatenate the objects.- Parameters:
object- Object to apply toString() to and outputobjects- Object... to apply toString() to and output
-
warn
Shows WARN output for the Object. It uses the toString() method.- Parameters:
object- Object to apply toString() to and output
-
warn
Shows WARN output for the given Object's. It uses the toString() method to concatenate the objects.- Parameters:
object- Object to apply toString() to and outputobjects- Object... to apply toString() to and output
-
isDebugEnabled
boolean isDebugEnabled()Use this method for computational demanding debug info. For example:if (logger.isDebugEnabled()) { logger.info("The 1056389822th prime that is used is: ", calculatePrime(1056389822)); }- Returns:
- true, if debug is enabled
-
setLevel
void setLevel(int level) Set the level of this logger. The level is provided in one of the constants:TRACE,DEBUG,INFO,WARN,ERROR,FATAL. After setting the level only messages above the specified level will be emitted.- Parameters:
level- the level
-
getLevel
int getLevel()Get the current level of this logger. The level is provided in one of the constants:TRACE,DEBUG,INFO,WARN,ERROR,FATAL.- Returns:
- the current level
-