com.townleyenterprises.trace
Class TraceCore

java.lang.Object
  extended bycom.townleyenterprises.trace.TraceCore
Direct Known Subclasses:
MethodTrace

public class TraceCore
extends java.lang.Object

This class represents the core of the original ErrorTrace class and contains the basic management of the trace facilities. Additionally, since it is being essentially reimplemented (again), it now supports a lot more fine-grained configuration options to allow the output to be controlled at run-time.

Since:
3.0
Version:
$Id: TraceCore.java,v 1.1 2004/11/27 17:32:50 atownley Exp $
Author:
Andrew S. Townley

Constructor Summary
protected TraceCore(java.lang.String name, int maturity)
          The constructor restricts creation of direct instances of the class except by subclasses.
 
Method Summary
 int getInstanceTraceLevel()
          This method returns the trace level for this specific instance.
static boolean getShowThreadNameAlways()
          Accessor to tell if we're displaying the thread name.
static boolean getShowTimestamp()
          Accessor to tell if we're displaying the timestamp.
static java.lang.String getTimestampFormat()
          Accessor for the timestamp format string.
static java.lang.String getTraceFile()
          This is the attribute accessor for the current trace file name.
static int getTraceLevel()
          This is the attribute accessor for the current global trace level for all instances.
static int getTraceLevel(java.lang.String name)
          This is the attribute accessor to retrieve the current trace level for the given trace object.
static java.io.PrintStream getTraceStream()
          This method returns a reference to the underlying trace PrintStream.
 void loadInstanceSettings(java.lang.String name, java.util.Properties props)
          This method is used to allow the instance to load the settings once it has been created.
static void loadSettings(java.util.Properties props)
          This method is used to load all of the configuration settings for ErrorTrace from the specified set of Properties.
 void printStackTrace(int threshold, java.lang.Throwable ex)
          This method is used to print the exception's stack trace to the trace log.
 void setInstanceTraceLevel(int l)
          This method is used to set the instance trace level for this object.
static void setShowThreadNameAlways(boolean x)
          Setter for showing the thread name.
static void setShowTimestamp(boolean x)
          Setter for the timestamp.
static void setTimestampFormat(java.lang.String fmt)
           
static void setTraceFile(java.lang.String filename, boolean append)
          This method is used to set the global trace file name for all objects.
static void setTraceLevel(int l)
          This method is used to set the global trace level for all objects.
static void setTraceLevel(java.lang.String name, int l)
          This method is used to set the specific trace level for the named trace object.
 void tprintln(int threshold, java.lang.String fmt)
          This is a short-hand way to call the tprintln method if no arguments are needed.
 void tprintln(int threshold, java.lang.String fmt, java.lang.Object[] args)
          This method is a generic method that is used by all of the other, simpler methods.
 boolean willTrace(int threshold)
          This method can be used to determine if trace messages will be printed for a certain threshold value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TraceCore

protected TraceCore(java.lang.String name,
                    int maturity)
The constructor restricts creation of direct instances of the class except by subclasses. For each instance created, it is automatically added to the map of configured instances so that finer control of the trace output can be provided.

Parameters:
name - the name of the class being traced
maturity - the maturity level of the class being traced
Method Detail

printStackTrace

public void printStackTrace(int threshold,
                            java.lang.Throwable ex)
This method is used to print the exception's stack trace to the trace log.

Parameters:
threshold - the trace threshold to print
ex - the exception to dump

tprintln

public void tprintln(int threshold,
                     java.lang.String fmt,
                     java.lang.Object[] args)
This method is a generic method that is used by all of the other, simpler methods. If the current trace level value is greater or equal to the maturity level * 10 plus the threshold level, the message will be printed.

Parameters:
threshold - the threshold at which the message should be traced
fmt - the message format string
args - any arguments to the message format

tprintln

public void tprintln(int threshold,
                     java.lang.String fmt)
This is a short-hand way to call the tprintln method if no arguments are needed.

Parameters:
threshold - the threshold at which the message should be traced
fmt - the message to be printed

willTrace

public boolean willTrace(int threshold)
This method can be used to determine if trace messages will be printed for a certain threshold value. This is especially useful at higher thresholds when dumping the contents of data structures. To dump the contents of an array to the trace log, the following mechanism should be used:
 	if(willTrace(10))
 	{
 		for(int i = 0; i < arr.length; ++i)
 		{
 			tprintln(10, "arr[" + i + "] = " + arr[i]);
 		}
 	}
 


getTraceLevel

public static int getTraceLevel()
This is the attribute accessor for the current global trace level for all instances.

Returns:
the current trace level

getTraceLevel

public static int getTraceLevel(java.lang.String name)
This is the attribute accessor to retrieve the current trace level for the given trace object.

Parameters:
name - the name of the trace object
Returns:
the trace level

getInstanceTraceLevel

public int getInstanceTraceLevel()
This method returns the trace level for this specific instance.

Returns:
the trace level

setTraceLevel

public static void setTraceLevel(int l)
This method is used to set the global trace level for all objects.

Parameters:
l - the new trace level

setTraceLevel

public static void setTraceLevel(java.lang.String name,
                                 int l)
This method is used to set the specific trace level for the named trace object.

Parameters:
name - the named object
l - the new trace level

setInstanceTraceLevel

public void setInstanceTraceLevel(int l)
This method is used to set the instance trace level for this object.

Parameters:
l - the new trace level

getTraceStream

public static java.io.PrintStream getTraceStream()
This method returns a reference to the underlying trace PrintStream.

Returns:
the trace stream

getShowTimestamp

public static boolean getShowTimestamp()
Accessor to tell if we're displaying the timestamp.


setShowTimestamp

public static void setShowTimestamp(boolean x)
Setter for the timestamp.


getShowThreadNameAlways

public static boolean getShowThreadNameAlways()
Accessor to tell if we're displaying the thread name.


setShowThreadNameAlways

public static void setShowThreadNameAlways(boolean x)
Setter for showing the thread name.


getTimestampFormat

public static java.lang.String getTimestampFormat()
Accessor for the timestamp format string.


setTimestampFormat

public static void setTimestampFormat(java.lang.String fmt)

getTraceFile

public static java.lang.String getTraceFile()
This is the attribute accessor for the current trace file name.

Returns:
the current trace file name

setTraceFile

public static void setTraceFile(java.lang.String filename,
                                boolean append)
This method is used to set the global trace file name for all objects.

Parameters:
filename - the name of the trace file
append - true to append to existing file

loadSettings

public static void loadSettings(java.util.Properties props)
This method is used to load all of the configuration settings for ErrorTrace from the specified set of Properties.

Parameters:
props - the properties to use to configure the trace utility.

loadInstanceSettings

public void loadInstanceSettings(java.lang.String name,
                                 java.util.Properties props)
This method is used to allow the instance to load the settings once it has been created. Each instance can have its own trace level independently controlled.

Parameters:
props - the properties


Copyright © 2002-2004, Andrew S. Townley and Townley Enterprises. All Rights Reserved.
This project is hosted on http://te-code.sourceforge.net.