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 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
  • Field Details

  • Constructor Details

    • DebugLogTee

      public DebugLogTee(String name, T tracer)
      Constructor expects the name of the tracer and the to be wrapped Tracer instance.
      Parameters:
      name - the name of the tracer
      tracer - the to be wrapped tracer (must not be a NullTracer instance)
  • Method Details

    • getSyncObject

      public final Object getSyncObject()
      Description copied from class: AbstractTracer
      Synchronizes access to the TracePrintStream. Clients with multiple TracingContexts should use it to synchronize their access to AbstractTracer.out().
      Overrides:
      getSyncObject in class AbstractTracer
      Returns:
      the syncObject
    • getBufferSize

      public final int getBufferSize()
      Description copied from class: AbstractTracer
      Gives the buffer size of the actual TracePrintStream.
      Overrides:
      getBufferSize in class AbstractTracer
      Returns:
      the bufferSize
    • isAutoflush

      public final boolean isAutoflush()
      Description copied from class: AbstractTracer
      Indicates whether the output stream will be flushed when leaving a method by AbstractTracer.wayout().
      Overrides:
      isAutoflush in class AbstractTracer
      Returns:
      the autoflush
    • isOpened

      public final boolean isOpened()
      Description copied from class: AbstractTracer
      Indicates whether the actual TracePrintStream is opened.
      Overrides:
      isOpened in class AbstractTracer
      Returns:
      the opened
    • getName

      public final String getName()
      Description copied from class: AbstractTracer
      The name of the tracer.
      Overrides:
      getName in class AbstractTracer
      Returns:
      the name
    • setBufferSize

      public final void setBufferSize(int bufferSize)
      Description copied from class: AbstractTracer
      Configures the buffer size of the actual TracePrintStream.
      Overrides:
      setBufferSize in class AbstractTracer
      Parameters:
      bufferSize - the bufferSize to set
    • setAutoflush

      public final void setAutoflush(boolean autoflush)
      Description copied from class: AbstractTracer
      Used during the configuration. Indicates whether the output stream will be flushed when leaving a method by AbstractTracer.wayout().
      Overrides:
      setAutoflush in class AbstractTracer
      Parameters:
      autoflush - the autoflush to set
    • readConfiguration

      protected final void readConfiguration(XPath xpath, Node node) throws XPathExpressionException, AbstractTracer.Exception
      Description copied from class: AbstractTracer
      Reads the configuration for this particular tracer instance by evaluating the given node with the given xpath engine.
      Overrides:
      readConfiguration in class AbstractTracer
      Parameters:
      xpath - the xpath engine
      node - the config node
      Throws:
      XPathExpressionException - indicates xpath problems
      AbstractTracer.Exception - indicates problems when configuring certain tracer instances
    • open

      public void open()
      Description copied from class: AbstractTracer
      Derived classes should provide code that opens the respective output streams.
      Specified by:
      open in class AbstractTracer
    • close

      public void close()
      Description copied from class: AbstractTracer
      Derived classes should provide code that closes the output streams.
      Specified by:
      close in class AbstractTracer
    • initCurrentTracingContext

      public final void initCurrentTracingContext()
      Description copied from class: AbstractTracer
      Initialises the current tracing context by taking the values for debugLevel and online from the configured debug map.
      Overrides:
      initCurrentTracingContext in class AbstractTracer
    • initCurrentTracingContext

      public final void initCurrentTracingContext(int debugLevel, boolean online)
      Description copied from class: AbstractTracer
      Initialises the current tracing context with the given debugLevel and online state.
      Overrides:
      initCurrentTracingContext in class AbstractTracer
      Parameters:
      debugLevel - controls the extent of the output
      online - 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 LogLevel
      message - the actual message
      clazz - 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 LogLevel
      throwable - references the to be logged info
      clazz - the class context of the message
    • entry

      public TraceMethod entry(String returnType, Class clazz, String methodSignature)
      Description copied from class: AbstractTracer
      Indicates an entering of a method which belongs to a class. If a TracingContext exists for the current thread a TraceMethod object will be created and thereupon pushed onto the stack of a ThreadMap.
      Overrides:
      entry in class AbstractTracer
      Parameters:
      returnType - the return type of the method as string representation
      clazz - the class to which that method belong
      methodSignature - 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: AbstractTracer
      Indicates an entering of a method which belongs to an object. If a TracingContext exists for the current thread a TraceMethod object will be created and thereupon pushed onto the stack of a ThreadMap.
      Overrides:
      entry in class AbstractTracer
      Parameters:
      returnType - the return type of the method as string representation
      object - the object that owns the method
      methodSignature - 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: AbstractTracer
      Indicates an entering of a method.
      Overrides:
      entry in class AbstractTracer
      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: AbstractTracer
      Logs a message with the given logLevel and the originating class.
      Overrides:
      logMessage in class AbstractTracer
      Parameters:
      logLevel - one of the predefined levels INFO, WARNING, ERROR, FATAL and SEVERE
      message - the to be logged message
      clazz - the originating class
      methodName - the originating method
    • logException

      public final void logException(LogLevel logLevel, Throwable throwable, Class clazz, String methodName)
      Description copied from class: AbstractTracer
      Logs an exception with the given logLevel and the originating class.
      Overrides:
      logException in class AbstractTracer
      Parameters:
      logLevel - one of the predefined levels INFO, WARNING, ERROR, FATAL and SEVERE
      throwable - the to be logged throwable
      clazz - the originating class
      methodName - the name of the relevant method
    • wayout

      public TraceMethod wayout()
      Description copied from class: AbstractTracer
      Indicates the exiting of a method.
      Overrides:
      wayout in class AbstractTracer
      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: AbstractTracer
      Returns some kind of an IndentablePrintStream based upon the the current managed stack size, the configured debug level and the online state of the current tracing context. This is the NullPrintStream if the stack size is greater than the debug level or if the thread is offline. Otherwise it's the TracePrintStream.
      Overrides:
      out in class AbstractTracer
      Returns:
      an IndentablePrintStream