Class FileTracer

java.lang.Object
de.christofreichardt.diagnosis.AbstractTracer
de.christofreichardt.diagnosis.file.FileTracer

public class FileTracer extends AbstractTracer
This particular tracer logs into the local file system.
Author:
Christof Reichardt
  • Field Details

    • traceLogfile

      protected File traceLogfile
      the actual log file
    • fileOutputStream

      protected FileOutputStream fileOutputStream
      the underlying OutputStream
    • byteLimit

      protected volatile long byteLimit
      indicates the lower bound of the number of bytes which leads to a log file rotation
    • logDirPath

      protected Path logDirPath
      denotes default log directory
    • counter

      protected int counter
      counts the number of file splittings
  • Constructor Details

    • FileTracer

      public FileTracer(String name)
      Constructor expects the preferably unique tracer name. This is at the same time the name of the logfile.
      Parameters:
      name - the name of the tracer
  • Method Details

    • getLogDirPath

      public Path getLogDirPath()
      Gives the path to the directory of the logfile.
      Returns:
      the logDirPath
    • setLogDirPath

      public void setLogDirPath(Path logDirPath)
      Sets the path to the directory of the logfile.
      Parameters:
      logDirPath - the logDirPath to set
    • getByteLimit

      public long getByteLimit()
      Indicates the lower bound of the number of bytes which leads to a log file rotation.
      Returns:
      the byteLimit
    • setByteLimit

      public void setByteLimit(long byteLimit)
      Sets the lower bound of the number of bytes which leads to a log file rotation.
      Parameters:
      byteLimit - the byteLimit to set
    • open

      public void open()
      Creates the underlying trace file and opens the associated trace streams. The file name will be assembled by the path to log directory and the name of the tracer.
      Specified by:
      open in class AbstractTracer
    • close

      public void close()
      Closes the associated trace streams.
      Specified by:
      close in class AbstractTracer
    • readConfiguration

      protected 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
    • checkLimit

      protected void checkLimit()
      Checks if the file size limit has been exceeded and splits the trace file if need be.
    • out

      public 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
    • logException

      public 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
    • logMessage

      public 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