public interface ILoggingTool
LoggingToolFactory
):
public class SomeClass { private static ILoggingTool logger; static { logger = LoggingToolFactory.createLoggingTool(SomeClass.class); } }There is no special reason not to make the logger private and static, as the logging information is closely bound to one specific Class, not subclasses and not instances.
The logger has five logging levels:
Consider that the 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 interfance, implementations
must also implement the static method create(Class<?>)
which
can be used by the LoggingToolFactory
to instantiate the
implementation.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_STACK_LENGTH
Default number of StackTraceElements to be printed by debug(Exception).
|
Modifier and Type | Method and Description |
---|---|
void |
debug(Object object)
Shows DEBUG output for the Object.
|
void |
debug(Object object,
Object... objects)
Shows DEBUG output for the given Object's.
|
void |
dumpClasspath()
Outputs the system property for java.class.path.
|
void |
dumpSystemProperties()
Outputs system properties for the operating system and the java
version.
|
void |
error(Object object)
Shows ERROR output for the Object.
|
void |
error(Object object,
Object... objects)
Shows ERROR output for the given Object's.
|
void |
fatal(Object object)
Shows FATAL output for the Object.
|
void |
info(Object object)
Shows INFO output for the Object.
|
void |
info(Object object,
Object... objects)
Shows INFO output for the given Object's.
|
boolean |
isDebugEnabled()
Use this method for computational demanding debug info.
|
void |
setStackLength(int length)
Sets the number of StackTraceElements to be printed in DEBUG mode when
calling
debug(Throwable) . |
void |
warn(Object object)
Shows WARN output for the Object.
|
void |
warn(Object object,
Object... objects)
Shows WARN output for the given Object's.
|
static final int DEFAULT_STACK_LENGTH
void dumpSystemProperties()
void setStackLength(int length)
debug(Throwable)
.
The default value is DEFAULT_STACK_LENGTH.length
- the new stack lengthDEFAULT_STACK_LENGTH
void dumpClasspath()
void debug(Object object)
Throwable
it will output the trace. Otherwise it will use the
toString() method.object
- Object to apply toString() too and outputvoid debug(Object object, Object... objects)
object
- Object to apply toString() too and outputobjects
- Object... to apply toString() too and outputvoid error(Object object)
object
- Object to apply toString() too and outputvoid error(Object object, Object... objects)
object
- Object to apply toString() too and outputobjects
- Object... to apply toString() too and outputvoid fatal(Object object)
object
- Object to apply toString() too and outputvoid info(Object object)
object
- Object to apply toString() too and outputvoid info(Object object, Object... objects)
object
- Object to apply toString() too and outputobjects
- Object... to apply toString() too and outputvoid warn(Object object)
object
- Object to apply toString() too and outputvoid warn(Object object, Object... objects)
object
- Object to apply toString() too and outputobjects
- Object... to apply toString() too and outputboolean isDebugEnabled()
if (logger.isDebugEnabled()) { logger.info("The 1056389822th prime that is used is: ", calculatePrime(1056389822)); }
Copyright © 2017. All Rights Reserved.