public final class TraceLogFactory
extends java.lang.Object
A factory class for creating TraceLog instances. Tracing in
the Toolkit is done via this class and TraceLog instances. The
trace logging capabilities provided by this class are not intended for use
outside the Toolkit, although applications are free to customize the way
trace is logged. Applications requiring logging would be much better served
by full-fledged logging capabilities such as those provided by Java 1.4's
java.util.logging package or the Apache log4j project.
When requesting a TraceLog instance with the
getTraceLogInstance method, the following steps are executed:
BASICFINE
FINERFINEST
FINESTNONE and tracing is
disabled.TraceLog to create is determined. If
the trace level is NONE, a NoOpTraceLog
instance is returned. If the logging class has been set with
setTraceLogClass(java.lang.Class)then an instance of this class is created and
returned. Otherwise, the system property
"com.entrust.toolkit.tracing.logclass" is queried. If this defines a sublcass
of TraceLog, then an instance of this class is created. If
the property is not set or does not define an appropriate class, and the
"com.entrust.toolkit.trace.filename" property is not specified, an instance
of ConsoleTraceLog is created and returned.
Note: The Toolkit classes that are capable of tracing
generally obtain a static TraceLog instance as part of a
static initializer block, and then use the same logger object for the rest of
the class's lifetime. This means that to enable tracing for a class, it must
be done before the class is loaded.
TraceLevel,
TraceLog| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
creationErrors()
Returns a String containing details of failures to allocate
TraceLog instances. |
void |
enableTracingForClass(java.lang.String className,
java.lang.String loggerName,
TraceLevel traceLevel)
Explicitly enable trace logging for a given class.
|
void |
enableTracingForClass(java.lang.String className,
TraceLog logger,
TraceLevel traceLevel)
Explicitly enable trace logging for a given class.
|
void |
enableTracingForPackage(java.lang.String packageName,
java.lang.String loggerName,
TraceLevel traceLevel)
Explicitly enable trace logging for a given package.
|
void |
enableTracingForPackage(java.lang.String packageName,
TraceLog logger,
TraceLevel traceLevel)
Explicitly enable trace logging for a given package.
|
static TraceLogFactory |
getInstance()
Returns an instance of
TraceLogFactory |
TraceLog |
getTraceLogInstance(java.lang.String name,
java.lang.String loggerName)
Get a
TraceLog instance for a given class or package name. |
void |
reset()
Reset this factory to its initial state.
|
void |
setTraceLogClass(java.lang.Class traceLogClass)
Set the class that will be used as the default for all future
TraceLog instances returned by this factory. |
public static TraceLogFactory getInstance()
TraceLogFactoryTraceLogFactorypublic void enableTracingForClass(java.lang.String className,
java.lang.String loggerName,
TraceLevel traceLevel)
className - the fully qualified name of class for which to enable trace
logging.loggerName - the name of the logger that will be created.traceLevel - the finest level at which to log trace information for the class.public void enableTracingForClass(java.lang.String className,
TraceLog logger,
TraceLevel traceLevel)
className - the fully qualified name of class for which to enable trace
logging.logger - the class that trace log messages will be sent to.traceLevel - the finest level at which to log trace information for the class.public void enableTracingForPackage(java.lang.String packageName,
java.lang.String loggerName,
TraceLevel traceLevel)
Note that all trace messages for the package will be sent to the same
TraceLog object.
packageName - the fully qualified pacakge name of package for which to enable
trace logging.loggerName - the name of the logger that will be created.traceLevel - the finest level at which to log trace information for the packge.public void enableTracingForPackage(java.lang.String packageName,
TraceLog logger,
TraceLevel traceLevel)
Note that all trace messages for the package will be sent to
logger.
packageName - the fully qualified pacakge name of package for which to enable
trace logging.logger - the class that trace log messages will be sent to.traceLevel - the finest level at which to log trace information for the
package.public TraceLog getTraceLogInstance(java.lang.String name, java.lang.String loggerName)
TraceLog instance for a given class or package name.
If a TraceLog instance has already been created for this
name, then it is returned instead of creating a new version. If tracing
has not been enabled for name, then a
NoOpTraceLog is returned.name - the name of the class or package for which to log trace messages.loggerName - the name of the logger, which can be placed in log messages to
help distinguish the source of the message. Can be
null.TraceLog instance for the given name.public void setTraceLogClass(java.lang.Class traceLogClass)
TraceLog instances returned by this factory.traceLogClass - the class to use for tracing. This must be a subclass of
TraceLog, if not this method has no effect.public void reset()
TraceLog classes.public java.lang.String creationErrors()
TraceLog instances. May be useful to find out why logging
is not enabled, as failure to create TraceLog instances
cannot be logged.TraceLog instances.