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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.christofreichardt.diagnosis.AbstractTracer
AbstractTracer.Exception
-
-
Field Summary
Fields Modifier and Type Field Description protected longbyteLimitindicates the lower bound of the number of bytes which leads to a log file rotationprotected intcountercounts the number of file splittingsprotected FileOutputStreamfileOutputStreamthe underlying OutputStreamprotected TracePrintStream.LockAccesslockAccessA helper object used to facilitate the roll-over of aLockfrom one instance of aTracePrintStreamto another instance.protected PathlogDirPathdenotes default log directoryprotected FiletraceLogfilethe actual log file-
Fields inherited from class de.christofreichardt.diagnosis.AbstractTracer
VERSION
-
-
Constructor Summary
Constructors Constructor Description FileTracer(String name)Constructor expects the preferably unique tracer name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckLimit()Checks if the file size limit has been exceeded and splits the trace file if need be.voidclose()Closes the associated trace streams.longgetByteLimit()Indicates the lower bound of the number of bytes which leads to a log file rotation.PathgetLogDirPath()Gives the path to the directory of the logfile.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()Creates the underlying trace file and opens the associated trace 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.voidrequestLockAccess(TracePrintStream.LockAccess lockAccess)TheTracePrintStreamuses this method to grant lock access to thisFileTracer.voidsetByteLimit(long byteLimit)Sets the lower bound of the number of bytes which leads to a log file rotation.voidsetLogDirPath(Path logDirPath)Sets the path to the directory of the logfile.-
Methods inherited from class de.christofreichardt.diagnosis.AbstractTracer
clearCurrentTracingContext, entry, entry, entry, formatStreamErrorState, formatVersionInfo, getBufferedOutputStream, getBufferSize, getLevel, getName, getNullPrintStream, getThreadMap, getTracePrintStream, initCurrentTracingContext, initCurrentTracingContext, isAutoflush, isOnline, isOpened, out, setAutoflush, setBufferedOutputStream, setBufferSize, setOpened, setTracePrintStream, wayout
-
-
-
-
Field Detail
-
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
-
lockAccess
protected TracePrintStream.LockAccess lockAccess
A helper object used to facilitate the roll-over of aLockfrom one instance of aTracePrintStreamto another instance.
-
-
Constructor Detail
-
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 Detail
-
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:
openin classAbstractTracer
-
close
public void close()
Closes the associated trace streams.- Specified by:
closein classAbstractTracer
-
readConfiguration
protected 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
-
requestLockAccess
public void requestLockAccess(TracePrintStream.LockAccess lockAccess)
TheTracePrintStreamuses this method to grant lock access to thisFileTracer.- Parameters:
lockAccess- a helper object with access to the employedLockof the enclosingTracePrintStream
-
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: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
-
logException
public 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
-
logMessage
public 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
-
-