Class TraceUtil


  • public class TraceUtil
    extends Object
    This class is used to set trace properties and print trace statements. The print method does the printing. All the methods are unsynchronized. Since setting of properties doesn't happen simultaneously with print in current usage, this is fine. The tracing should be enabled/disabled by calling Configuration.enableTrace()/disableTrace() prior to any operation on TraceUtil. It uses TraceRecordFormatter for formatting the trace record.
    Version:
    1.0
    Author:
    Kannan Srinivasan
    • Constructor Detail

      • TraceUtil

        public TraceUtil()
    • Method Detail

      • init

        public static void init​(PrintWriter traceWriter)
        Initialises the trace class with given output writer.
        Parameters:
        traceWriter - an PrintWriter value
      • setTraceWriter

        public static void setTraceWriter​(PrintWriter traceWriter)
        Sets the output writer. By default the output writer is set to Stdout.
        Parameters:
        traceWriter - an PrintWriter value
      • getTraceWriter

        public static PrintWriter getTraceWriter()
        Gets the current output writer.
        Returns:
        an PrintWriter value
      • getCurrentTraceLevel

        public static int getCurrentTraceLevel()
        Gets the current trace level. Returns an integer as per the TraceLevel constants.
        Returns:
        an int value
      • setCurrentTraceLevel

        public static void setCurrentTraceLevel​(int traceLevel)
                                         throws InvalidTraceLevelException
        Sets the current trace level. The argument is tested for its validity and trace level is set. Else an exception is raised.
        Parameters:
        traceLevel - an int value
        Throws:
        InvalidTraceLevelException - if an error occurs
      • print

        public static void print​(int traceLevel,
                                 PrintWriter outWriter,
                                 Object tid,
                                 Object origin,
                                 String msg)
        This method formats and writes the trace record to output writer. The method is called with a tracelevel, which is checked with current trace level and if found equal or higher, the print is carried out. This method takes an PrintWriter also, which is used to write the output. This given outputWriter would override the set outputWriter. The origin object is printed using its toString() method.
        Parameters:
        traceLevel - an int value
        outWriter - an PrintWriter value
        tid - an Object value
        origin - an Object value
        msg - a String value
      • print

        public static void print​(int traceLevel,
                                 Object origin,
                                 String msg)
        This method formats and writes the trace record to current output writer. The method is called with a tracelevel, which is checked with current trace level and if found equal or higher, the print is carried out. This method doesn't take a otid and tries to recover it from current obejct asscociated with this thread
        Parameters:
        traceLevel - an int value
        origin - an Object value
        msg - a String value
      • print

        public static void print​(int traceLevel,
                                 Object tid,
                                 Object origin,
                                 String msg)
        This method formats and writes the trace record to current output writer. The method is called with a tracelevel, which is checked with current trace level and if found equal or higher, the print is carried out. This uses the currently set output writer to write the trace output.
        Parameters:
        traceLevel - an int value
        tid - an Object value
        origin - an Object value
        msg - a String value
      • getFieldDelimiter

        public static char getFieldDelimiter()
        Gets the current field delimiter used in formatting trace record. The default is ':'.
        Returns:
        a char value
      • setFieldDelimiter

        public static void setFieldDelimiter​(char delimiter)
        Sets the current field delimiter.
        Parameters:
        delimiter - a char value
      • getTraceRecordTag

        public static String getTraceRecordTag()
        Gets the current trace record tag used in formatting of trace record. The default is 'iAS_JTS_Trace> '.
        Returns:
        a String value
      • setTraceRecordTag

        public static void setTraceRecordTag​(String traceRecordTag)
        Sets the trace record tag.
        Parameters:
        traceRecordTag - a String value
      • getXAExceptionInfo

        public static String getXAExceptionInfo​(XAException exception,
                                                Logger logger)
        Returns details about Oracle XAException if available. Returns an default message if it is not Oracle XAException
        Parameters:
        exception - an XAException to get info from
        logger - the Logger to use to report errors extracting the data
        Returns:
        a String value