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
public abstract class DebugLogTee<T extends AbstractTracer> extends AbstractTracer
An abstract base class which provides the environment to connect additionally to another log system, such as log4j. This class honors the contract of theAbstractTracerbase class but does so by wrapping and delegating to anotherAbstractTracer. 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 aNullTracer. An adapter which is only interested in logging messages and wants to discard the additional tracing information altogether should be derived directly from theNullTracer.- Author:
- Christof Reichardt
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.christofreichardt.diagnosis.AbstractTracer
AbstractTracer.Exception
-
-
Field Summary
Fields Modifier and Type Field Description protected TtracerSome tracer.-
Fields inherited from class de.christofreichardt.diagnosis.AbstractTracer
VERSION
-
-
Constructor Summary
Constructors Constructor Description DebugLogTee(String name, T tracer)Constructor expects the name of the tracer and the to be wrapped Tracer instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected abstract voidadapt(LogLevel logLevel, String message, Class<?> clazz)Derived classes should provide code which routes the given message with the denoted logLevel and class to the desired log system.protected abstract voidadapt(LogLevel logLevel, Throwable throwable, Class<?> clazz)Derived 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.TraceMethodentry(String methodSignature)Deprecated.TraceMethodentry(String returnType, Class<?> clazz, String methodSignature)Indicates an entering of a method which belongs to a class.TraceMethodentry(String returnType, Object object, String methodSignature)Indicates an entering of a method which belongs to an object.intgetBufferSize()Gives the buffer size of the actualTracePrintStream.StringgetName()The name of the tracer.voidinitCurrentTracingContext()Initialises the current tracing context by taking the values for debugLevel and online from the configured debug map.voidinitCurrentTracingContext(int debugLevel, boolean online)Initialises the current tracing context with the given debugLevel and online state.booleanisAutoflush()Indicates whether the output stream will be flushed when leaving a method byAbstractTracer.wayout().booleanisOpened()Indicates whether the actualTracePrintStreamis opened.voidlogException(LogLevel logLevel, Throwable throwable, Class<?> clazz, String methodName)Logs an exception with the given logLevel and the originating class.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.IndentablePrintStreamout()Returns some kind ofIndentablePrintStreambased upon the current managed stack size, the configured debug level and the online state of the current tracing context.protected voidreadConfiguration(XPath xpath, Node node)Reads the configuration for this particular tracer instance by evaluating the given node with the given xpath engine.voidsetAutoflush(boolean autoflush)Used during the configuration.voidsetBufferSize(int bufferSize)Configures the buffer size of the actualTracePrintStream.TraceMethodwayout()Indicates the exiting of a method.-
Methods inherited from class de.christofreichardt.diagnosis.AbstractTracer
clearCurrentTracingContext, formatStreamErrorState, formatVersionInfo, getBufferedOutputStream, getLevel, getNullPrintStream, getThreadMap, getTracePrintStream, isOnline, out, setBufferedOutputStream, setOpened, setTracePrintStream
-
-
-
-
Field Detail
-
tracer
protected final T extends AbstractTracer tracer
Some tracer.
-
-
Method Detail
-
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
public final String 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
protected abstract void adapt(LogLevel logLevel, String message, Class<?> clazz)
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
protected abstract void adapt(LogLevel logLevel, Throwable throwable, Class<?> clazz)
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
public TraceMethod entry(String returnType, Class<?> clazz, String methodSignature)
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
public TraceMethod entry(String returnType, Object object, String methodSignature)
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 public TraceMethod entry(String methodSignature)
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
public final void logMessage(LogLevel logLevel, String message, Class<?> clazz, String methodName)
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
public TraceMethod 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
public final IndentablePrintStream out()
Description copied from class:AbstractTracerReturns some kind ofIndentablePrintStreambased upon 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
-
-