Package de.christofreichardt.diagnosis
Class DebugLogTee<T extends AbstractTracer>
java.lang.Object
de.christofreichardt.diagnosis.AbstractTracer
de.christofreichardt.diagnosis.DebugLogTee<T>
- Type Parameters:
T- The actual tracer type
- Direct Known Subclasses:
FileTracerLogTee
An abstract base class which provides the environment to connect additionally to another log system, such as log4j.
This class honors the contract of the
AbstractTracer base class but does so by wrapping and delegating to another AbstractTracer.
Besides two abstract adapt methods must be implemented to route log messages to the desired log system. Note that the wrapped tracer instance must
not be a NullTracer. An adapter which is only interested in logging messages and wants to discard the additional tracing information altogether
should be derived directly from the NullTracer.- Author:
- Christof Reichardt
-
Nested Class Summary
Nested classes/interfaces inherited from class de.christofreichardt.diagnosis.AbstractTracer
AbstractTracer.Exception -
Field Summary
FieldsFields inherited from class de.christofreichardt.diagnosis.AbstractTracer
VERSION -
Constructor Summary
ConstructorsConstructorDescriptionDebugLogTee(String name, T tracer) Constructor expects the name of the tracer and the to be wrapped Tracer instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidDerived classes should provide code which routes the given message with the denoted logLevel and class to the desired log system.protected abstract voidDerived classes should provide code which routes the given throwable with the denoted logLevel and class to the desired log system.voidclose()Derived classes should provide code that closes the output streams.Deprecated.Indicates an entering of a method which belongs to a class.Indicates an entering of a method which belongs to an object.final intGives the buffer size of the actualTracePrintStream.final StringgetName()The name of the tracer.final ObjectSynchronizes access to theTracePrintStream.final voidInitialises the current tracing context by taking the values for debugLevel and online from the configured debug map.final voidinitCurrentTracingContext(int debugLevel, boolean online) Initialises the current tracing context with the given debugLevel and online state.final booleanIndicates whether the output stream will be flushed when leaving a method byAbstractTracer.wayout().final booleanisOpened()Indicates whether the actualTracePrintStreamis opened.final voidlogException(LogLevel logLevel, Throwable throwable, Class clazz, String methodName) Logs an exception with the given logLevel and the originating class.final voidlogMessage(LogLevel logLevel, String message, Class clazz, String methodName) Logs a message with the given logLevel and the originating class.voidopen()Derived classes should provide code that opens the respective output streams.final IndentablePrintStreamout()Returns some kind of anIndentablePrintStreambased upon the the current managed stack size, the configured debug level and the online state of the current tracing context.protected final voidreadConfiguration(XPath xpath, Node node) Reads the configuration for this particular tracer instance by evaluating the given node with the given xpath engine.final voidsetAutoflush(boolean autoflush) Used during the configuration.final voidsetBufferSize(int bufferSize) Configures the buffer size of the actualTracePrintStream.wayout()Indicates the exiting of a method.Methods inherited from class de.christofreichardt.diagnosis.AbstractTracer
clearCurrentTracingContext, formatStreamErrorState, formatVersionInfo, getBufferedOutputStream, getNullPrintStream, getThreadMap, getTracePrintStream, out, setBufferedOutputStream, setOpened, setTracePrintStream, substitute
-
Field Details
-
tracer
Some tracer.
-
-
Constructor Details
-
DebugLogTee
Constructor expects the name of the tracer and the to be wrapped Tracer instance.- Parameters:
name- the name of the tracertracer- the to be wrapped tracer (must not be a NullTracer instance)
-
-
Method Details
-
getSyncObject
Description copied from class:AbstractTracerSynchronizes access to theTracePrintStream. Clients with multipleTracingContexts should use it to synchronize their access toAbstractTracer.out().- Overrides:
getSyncObjectin classAbstractTracer- Returns:
- the syncObject
-
getBufferSize
public final int getBufferSize()Description copied from class:AbstractTracerGives the buffer size of the actualTracePrintStream.- Overrides:
getBufferSizein classAbstractTracer- Returns:
- the bufferSize
-
isAutoflush
public final boolean isAutoflush()Description copied from class:AbstractTracerIndicates whether the output stream will be flushed when leaving a method byAbstractTracer.wayout().- Overrides:
isAutoflushin classAbstractTracer- Returns:
- the autoflush
-
isOpened
public final boolean isOpened()Description copied from class:AbstractTracerIndicates whether the actualTracePrintStreamis opened.- Overrides:
isOpenedin classAbstractTracer- Returns:
- the opened
-
getName
Description copied from class:AbstractTracerThe name of the tracer.- Overrides:
getNamein classAbstractTracer- Returns:
- the name
-
setBufferSize
public final void setBufferSize(int bufferSize) Description copied from class:AbstractTracerConfigures the buffer size of the actualTracePrintStream.- Overrides:
setBufferSizein classAbstractTracer- Parameters:
bufferSize- the bufferSize to set
-
setAutoflush
public final void setAutoflush(boolean autoflush) Description copied from class:AbstractTracerUsed during the configuration. Indicates whether the output stream will be flushed when leaving a method byAbstractTracer.wayout().- Overrides:
setAutoflushin classAbstractTracer- Parameters:
autoflush- the autoflush to set
-
readConfiguration
protected final void readConfiguration(XPath xpath, Node node) throws XPathExpressionException, AbstractTracer.Exception Description copied from class:AbstractTracerReads the configuration for this particular tracer instance by evaluating the given node with the given xpath engine.- Overrides:
readConfigurationin classAbstractTracer- Parameters:
xpath- the xpath enginenode- the config node- Throws:
XPathExpressionException- indicates xpath problemsAbstractTracer.Exception- indicates problems when configuring certain tracer instances
-
open
public void open()Description copied from class:AbstractTracerDerived classes should provide code that opens the respective output streams.- Specified by:
openin classAbstractTracer
-
close
public void close()Description copied from class:AbstractTracerDerived classes should provide code that closes the output streams.- Specified by:
closein classAbstractTracer
-
initCurrentTracingContext
public final void initCurrentTracingContext()Description copied from class:AbstractTracerInitialises the current tracing context by taking the values for debugLevel and online from the configured debug map.- Overrides:
initCurrentTracingContextin classAbstractTracer
-
initCurrentTracingContext
public final void initCurrentTracingContext(int debugLevel, boolean online) Description copied from class:AbstractTracerInitialises the current tracing context with the given debugLevel and online state.- Overrides:
initCurrentTracingContextin classAbstractTracer- Parameters:
debugLevel- controls the extent of the outputonline- a value of false delivers no output of the current thread at all whereas a value of true delivers output controlled by debugLevel
-
adapt
Derived classes should provide code which routes the given message with the denoted logLevel and class to the desired log system.- Parameters:
logLevel- the to be translated LogLevelmessage- the actual messageclazz- the class context of the message
-
adapt
Derived classes should provide code which routes the given throwable with the denoted logLevel and class to the desired log system.- Parameters:
logLevel- the to be translated LogLevelthrowable- references the to be logged infoclazz- the class context of the message
-
entry
Description copied from class:AbstractTracerIndicates an entering of a method which belongs to a class. If aTracingContextexists for the current thread aTraceMethodobject will be created and thereupon pushed onto the stack of aThreadMap.- Overrides:
entryin classAbstractTracer- Parameters:
returnType- the return type of the method as string representationclazz- the class to which that method belongmethodSignature- the remaining method signature (without return type) inclusive parameter as string representation- Returns:
- the TraceMethod which has been put onto the stack - a mere data object for internal use primarily. May be null.
-
entry
Description copied from class:AbstractTracerIndicates an entering of a method which belongs to an object. If aTracingContextexists for the current thread aTraceMethodobject will be created and thereupon pushed onto the stack of aThreadMap.- Overrides:
entryin classAbstractTracer- Parameters:
returnType- the return type of the method as string representationobject- the object that owns the methodmethodSignature- the remaining method signature (without return type) inclusive parameter as string representation- Returns:
- the TraceMethod which has been put onto the stack - a mere data object for internal use primarily. May be null.
-
entry
Deprecated.Description copied from class:AbstractTracerIndicates an entering of a method.- Overrides:
entryin classAbstractTracer- Parameters:
methodSignature- the signature of the method as string representation- Returns:
- the TraceMethod which has been put onto the stack - a mere data object for internal use primarily. May be null.
-
logMessage
Description copied from class:AbstractTracerLogs a message with the given logLevel and the originating class.- Overrides:
logMessagein classAbstractTracer- Parameters:
logLevel- one of the predefined levels INFO, WARNING, ERROR, FATAL and SEVEREmessage- the to be logged messageclazz- the originating classmethodName- the originating method
-
logException
public final void logException(LogLevel logLevel, Throwable throwable, Class clazz, String methodName) Description copied from class:AbstractTracerLogs an exception with the given logLevel and the originating class.- Overrides:
logExceptionin classAbstractTracer- Parameters:
logLevel- one of the predefined levels INFO, WARNING, ERROR, FATAL and SEVEREthrowable- the to be logged throwableclazz- the originating classmethodName- the name of the relevant method
-
wayout
Description copied from class:AbstractTracerIndicates the exiting of a method.- Overrides:
wayoutin classAbstractTracer- Returns:
- the TraceMethod which has been popped from the stack - a mere data object for internal use primarily. May be null.
-
out
Description copied from class:AbstractTracerReturns some kind of anIndentablePrintStreambased upon the the current managed stack size, the configured debug level and the online state of the current tracing context. This is theNullPrintStreamif the stack size is greater than the debug level or if the thread is offline. Otherwise it's theTracePrintStream.- Overrides:
outin classAbstractTracer- Returns:
- an
IndentablePrintStream
-