All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class phil.util.traceJ.Trace

java.lang.Object
   |
   +----phil.util.traceJ.Trace

public class Trace
extends Object
implements Traceable
Provides trace functionality for single-threaded Java applications. If used to trace multiple threads of an application, then the trace depth is uselesss and may in fact generate out-of-bounds errors.

A multi-threaded version is available. Please contact me at philreed@ticnet.com for information.

NOTE: Example program source is included in examples\TestTrace.java

USAGE NOTES:   Trace.method() must be called before any trace statements in the body of a method will be executed. Likewise, Trace.constructor() must be called before any trace statements in the body of a class constructor.


Variable Index

 o active
The current state of the trace (does it have valid bits?).
 o bits
The trace bits currently in use.
 o currentClass
The name of the current class.
 o currentDepth
The current depth (in traced classes/methods).
 o methodStack
The name of the current method.
 o open
The current state of the output stream.
 o outputName
The name of the trace output file.
 o threadName
The name of the thread/component.

Constructor Index

 o Trace()
Opens a trace output stream to standard output.
 o Trace(int)
Opens a trace output stream to standard output and activates traces using the specified bits.
 o Trace(String)
Opens a trace output stream.
 o Trace(String, int)
Opens a trace output stream and activates traces using the specified bits.

Method Index

 o close()
Deactivates traces.
 o constructor(Object)
Used to enable tracing of a class constructor.
 o dump(TraceToken, char[])
Generates a formatted hex dump of buffer and adds it to the output stream.
 o dump(TraceToken, char[], int, int)
Generates a formatted hex dump of buffer from offset for length and adds it to the output stream.
 o dump(TraceToken, String)
Generates a formatted hex dump of buffer and adds it to the output stream.
 o dump(TraceToken, String, int, int)
Generates a formatted hex dump of buffer from offset for length and adds it to the output stream.
 o dumpStack()
Dumps the contents of the method call stack to the trace output stream in reverse order.
 o dumpTraceBits()
Dumps the active trace bits to the output stream.
 o exit(TraceToken)
Removes the current method from the method stack and indicates its exit in the trace output stream.
 o exit(TraceToken, boolean)
Removes the current method from the method stack and indicates its exit in the trace output stream.
 o field(TraceToken, String, int)
Prints the name and contents of a field to the trace output stream.
 o field(TraceToken, String, Object)
Prints the name and contents of a field to the trace output stream.
 o field(TraceToken, String, String)
Prints the name and contents of a field to the trace output stream.
 o getBitArray()
Generates a String array containing the names of the active trace bits.
 o getBits()
Returns the active trace bits.
 o getMethodStack()
Returns a Vector containing Strings representing the method call stack.
 o method(Object, String, int)
Adds the current method to the method stack and indicates its entry in the trace output stream.
 o print(TraceToken, String)
Prints the specified string to the trace output stream.
 o print(TraceToken, String, int)
Prints the specified string to the trace output stream.
 o set(int)
Sets the trace bits in use to those specified.
 o test(int)
Tests if a bit or set of bits is currently set.

Variables

 o active
 protected static boolean active
The current state of the trace (does it have valid bits?).

 o open
 protected static boolean open
The current state of the output stream.

 o bits
 protected static int bits
The trace bits currently in use.

 o currentDepth
 protected static int currentDepth
The current depth (in traced classes/methods).

 o outputName
 protected static String outputName
The name of the trace output file.

 o threadName
 protected static String threadName
The name of the thread/component.

 o methodStack
 protected static Vector methodStack
The name of the current method.

 o currentClass
 protected String currentClass
The name of the current class.

Constructors

 o Trace
 public Trace()
Opens a trace output stream to standard output.

 o Trace
 public Trace(int bits)
Opens a trace output stream to standard output and activates traces using the specified bits.

Parameters:
bits - an int value representing trace bits.
 o Trace
 public Trace(String traceName)
Opens a trace output stream. If traceName is a null string (length=0) then a TraceGUI object is created and used for output.

Parameters:
traceName - a String containing the file name for trace output.
 o Trace
 public Trace(String traceName,
              int bits)
Opens a trace output stream and activates traces using the specified bits. If traceName is a null string (length=0) then a TraceGUI object is created and used for output.

Parameters:
traceName - a String containing the file name for trace output.
bits - an int value representing trace bits.

Methods

 o close
 public void close()
Deactivates traces. The output stream is flushed and closed.

 o constructor
 public TraceToken constructor(Object traceObject)
Used to enable tracing of a class constructor. Tracing is only performed if the TR_CONSTRUCT bit is enabled.

Parameters:
traceObject - The object being constructed. Suggest using this.
Returns:
The token used for all trace operations in the constructor.
 o dump
 public void dump(TraceToken token,
                  char buffer[])
Generates a formatted hex dump of buffer and adds it to the output stream.

Parameters:
token - The TraceToken used by the current constructor or method.
buffer - char[]
 o dump
 public void dump(TraceToken token,
                  char buffer[],
                  int offset,
                  int length)
Generates a formatted hex dump of buffer from offset for length and adds it to the output stream.

Parameters:
token - The TraceToken used by the current constructor or method.
buffer - char[]
offset - int
length - int
 o dump
 public void dump(TraceToken token,
                  String buffer)
Generates a formatted hex dump of buffer and adds it to the output stream.

Parameters:
token - The TraceToken used by the current constructor or method.
buffer - java.lang.String
 o dump
 public void dump(TraceToken token,
                  String buffer,
                  int offset,
                  int length)
Generates a formatted hex dump of buffer from offset for length and adds it to the output stream.

Parameters:
token - The TraceToken used by the current constructor or method.
buffer - char[]
 o dumpStack
 public void dumpStack()
Dumps the contents of the method call stack to the trace output stream in reverse order.

 o dumpTraceBits
 protected void dumpTraceBits()
Dumps the active trace bits to the output stream.

 o exit
 public void exit(TraceToken token)
Removes the current method from the method stack and indicates its exit in the trace output stream.

Parameters:
token - The TraceToken used by the current constructor or method.
 o exit
 public void exit(TraceToken token,
                  boolean value)
Removes the current method from the method stack and indicates its exit in the trace output stream.

Parameters:
token - The TraceToken used by the current constructor or method.
value - boolean
 o field
 public void field(TraceToken token,
                   String fieldName,
                   int value)
Prints the name and contents of a field to the trace output stream.

Parameters:
token - The TraceToken used by the current constructor or method.
fieldName - java.lang.String
value - int
 o field
 public void field(TraceToken token,
                   String fieldName,
                   Object value)
Prints the name and contents of a field to the trace output stream.

Parameters:
token - The TraceToken used by the current constructor or method.
fieldName - java.lang.String
value - java.lang.Object
 o field
 public void field(TraceToken token,
                   String fieldName,
                   String value)
Prints the name and contents of a field to the trace output stream.

Parameters:
token - The TraceToken used by the current constructor or method.
fieldName - java.lang.String
value - java.lang.String
 o getBitArray
 protected String[] getBitArray()
Generates a String array containing the names of the active trace bits.

Returns:
java.lang.String[]
 o getBits
 public int getBits()
Returns the active trace bits.

Returns:
int
 o getMethodStack
 public Vector getMethodStack()
Returns a Vector containing Strings representing the method call stack. The elements are in call order with the last element representing the most recent method traced.

Returns:
java.util.Vector
 o method
 public TraceToken method(Object caller,
                          String methodName,
                          int bits)
Adds the current method to the method stack and indicates its entry in the trace output stream.

Parameters:
caller - The object being traced. Suggest using this.
methodName - a String containing the name of the traced method.
bits - an integer value representing trace bits for which this method should be traced.
Returns:
TraceToken The token used for all trace operations in the method.
 o print
 public void print(TraceToken token,
                   String text)
Prints the specified string to the trace output stream. The string is appended to a trace prefix string prior to output.

Parameters:
token - The TraceToken used by the current constructor or method.
text - The string to print.
 o print
 public void print(TraceToken token,
                   String text,
                   int msgType)
Prints the specified string to the trace output stream. The string is appended to a trace prefix string prior to output and, if msgType contains a valid, active type, an eye-catcher string is also included.

Parameters:
token - The TraceToken used by the current constructor or method.
text - The string to print.
msgType - int value, TR_DIAG or TR_COMMENT, any other value causes the default print format to be used.
 o set
 public void set(int bits)
Sets the trace bits in use to those specified.

Parameters:
bits - int
 o test
 public boolean test(int bits)
Tests if a bit or set of bits is currently set.

Parameters:
bits - int
Returns:
boolean

All Packages  Class Hierarchy  This Package  Previous  Next  Index