public class Trace
extends java.lang.Object
implements java.lang.Runnable
The caller can enable or disable all tracing or specific trace categories. Enabling or disabling one category does not affect other categories. Once appropriate category traces are enabled, trace must be turned on to get trace data. For example,
// By default, trace is disabled for all categories and // tracing is off. .. Trace.setTraceErrorOn(true); // Enable error messages Trace.setTraceWarningOn(true); // Enable warning messages Trace.setTraceOn(true); // Turn trace on for all // Enabled categories .. Trace.setTraceOn(false); // Turn trace off .. Trace.setTraceOn(true); // Turn trace back on .. Trace.setTraceInformationOn(true); // Enable informational messages. // Since trace is still on, no // other action is required to // get this data .. Trace.setTraceWarningOn(false); // Disable warning messages. Since // trace is still on, the other // categories will still be loggedThe traces are logged to standard out by default. A file name can be provided to log to a file. File logging is only possible in an application as most browsers do not allow access to the local file system.
Trace data can also be specified by component. Trace data is always written to the default log but component tracing provides a way to write trace data to a separate log.
The following example logs data for Function123 into log file C:\Function123.log, and logs data for Function456 into log file C:\Function456.log. Data for these two components is also traced to the normal trace file (standard output in this case since that is the default for normal tracing). The result is three sets of data -- a file containing trace data for only Function123, a file containing trace data for only Function456, and standard output which records all trace data. In the example a Java String object is used to indicate the component, but any object can be used.
// tracing is off by default .. String cmpF123 = "Function123"; // More efficient to create an object String cmpF456 = "Function456"; // than many String literals. // Specify where data should go // for the two components. Trace.setFileName(cmpF123, "C:\\Function123.log"); Trace.setFileName(cmpF456, "C:\\Function456.log"); Trace.setTraceInformationOn(true); // Trace only the information category. Trace.setTraceOn(true); // Turn tracing on. .. Trace.log(cmpF123, Trace.INFORMATION, "I am here"); .. Trace.log(cmpF456, Trace.INFORMATION, "I am there"); .. Trace.log(cmpF456, Trace.INFORMATION, "I am everywhere"); .. Trace.setTraceOn(false); // Turn tracing off.
Component tracing provides an easy way to write application specific trace data to a log or standard output. Any application and the Toolbox classes can use trace to log messages. With component tracing, application data can be easily separated from other data. For example,
String myComponent = "com.myCompany"; // More efficient to create an object // than many String literals. Trace.setFileName("C:\\bit.bucket"); // Send default trace data to // a file. Trace.setTraceInformationOn(true); // Enable information messages. Trace.setTraceOn(true); // Turn trace on. ... // Since no file was specified, data for // myComponent goes to standard output. // Other information messages are sent to a file. Trace.log(myComponent, Trace.INFORMATION, "my trace data");
Two techniques can be used to log information:
.. // Let the Trace method determine if logging should occur Trace.log(Trace.INFORMATION, "I got here..."); .. // Pre-determine if we should log. This may be more efficient // if a lot of processing in needed to generate the trace data. if (Trace.isTraceOn() && Trace.isTraceInformationOn()) { Trace.log(Trace.INFORMATION, "I got here..."); }
It is suggested that programs provide some mechanism to enable tracing at run-time, so that the modification and recompilation of code is not necessary. Two possibilities for that mechanism are a command line argument (for applications) or a menu option (for applications and applets).
In addition, tracing can be set using the "com.ibm.as400.access.Trace.category" and "com.ibm.as400.access.Trace.file" system properties.
Note: This class can exploit a standard Java Logger if one is defined in the JVM (per JSR 47, package java.util.logging, added in J2SE 1.4).
See LOGGER_NAME
.
Modifier and Type | Field and Description |
---|---|
static int |
CONVERSION
'Character set conversion' trace category.
|
static int |
DATASTREAM
'Data stream' trace category.
|
static int |
DIAGNOSTIC
'Diagnostic message' trace category.
|
static int |
ERROR
'Error message' trace category.
|
static int |
INFORMATION
'Information message' trace category.
|
static int |
JDBC
'JDBC' trace category.
|
static java.lang.String |
LOGGER_NAME
Name of the instance of java.util.logging.Logger that the Toolbox uses.
|
static int |
PCML
'PCML' trace category.
|
static int |
PROXY
'Proxy' trace category.
|
static int |
WARNING
'Warning message' trace category.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
getFileName()
Returns the trace file name.
|
static java.lang.String |
getFileName(java.lang.Object component)
Returns the trace file name for the specified component.
|
static java.io.PrintWriter |
getPrintWriter()
Returns the PrintWriter object.
|
static java.io.PrintWriter |
getPrintWriter(java.lang.Object component)
Returns the print writer object for the specified component.
|
static boolean |
isTraceAllOn()
Indicates if all of the tracing categories are enabled.
|
static boolean |
isTraceConversionOn()
Indicates if character set conversion tracing is enabled.
|
static boolean |
isTraceDatastreamOn()
Indicates if data stream tracing is enabled.
|
static boolean |
isTraceDiagnosticOn()
Indicates if diagnostic tracing is enabled.
|
static boolean |
isTraceErrorOn()
Indicates if error tracing is enabled.
|
static boolean |
isTraceInformationOn()
Indicates if information tracing is enabled.
|
static boolean |
isTraceJDBCOn()
Indicates if JDBC tracing is enabled.
|
static boolean |
isTraceOn()
Indicates if overall tracing is enabled.
|
static boolean |
isTraceOn(int category)
Indicates if tracing is enabled for the specified category.
|
static boolean |
isTracePCMLOn()
Indicates if PCML tracing is enabled.
|
static boolean |
isTraceProxyOn()
Indicates if proxy tracing is enabled.
|
static boolean |
isTraceThreadOn()
Indicates if thread tracing is enabled.
|
static boolean |
isTraceWarningOn()
Indicates if warning tracing is enabled.
|
static void |
log(int category,
java.lang.Object source,
java.lang.String message)
Logs a message in the specified category.
|
static void |
log(int category,
java.lang.Object source,
java.lang.String message,
boolean value)
Logs a message and a boolean value in the specified category.
|
static void |
log(int category,
java.lang.Object source,
java.lang.String message,
byte[] data)
Logs a message and byte data in the specified category.
|
static void |
log(int category,
java.lang.Object source,
java.lang.String message,
int value)
Logs a message and an integer value in the specified category.
|
static void |
log(int category,
java.lang.Object source,
java.lang.String message,
java.lang.Throwable e)
Logs a message in the specified category.
|
static void |
log(int category,
java.lang.String message)
Logs a message in the specified category.
|
static void |
log(int category,
java.lang.String message,
boolean value)
Logs a message and a boolean value in the specified category.
|
static void |
log(int category,
java.lang.String message,
byte[] data)
Logs a message and byte data in the specified category.
|
static void |
log(int category,
java.lang.String message,
byte[] data,
int offset,
int length)
Logs a message and byte data in the specified category.
|
static void |
log(int category,
java.lang.String message,
int value)
Logs a message and an integer value in the specified category.
|
static void |
log(int category,
java.lang.String message,
java.lang.String value)
Logs a message and a String value in the specified category.
|
static void |
log(int category,
java.lang.String message,
java.lang.Throwable e)
Logs a message in the specified category.
|
static void |
log(int category,
java.lang.Throwable e)
Logs a message in the specified category.
|
static void |
log(java.lang.Object component,
int category,
java.lang.Object source,
java.lang.String message)
Logs a message for the specified component for the specified category.
|
static void |
log(java.lang.Object component,
int category,
java.lang.String message)
Logs a message for the specified component for the specified category.
|
static void |
log(java.lang.Object component,
int category,
java.lang.String message,
boolean value)
Logs a message and a boolean value in the specified category
for the specified component.
|
static void |
log(java.lang.Object component,
int category,
java.lang.String message,
byte[] data)
Logs a message and byte data in the specified category for the
specified component.
|
static void |
log(java.lang.Object component,
int category,
java.lang.String message,
byte[] data,
int offset,
int length)
Logs a message and byte data in the specified category
for the specified component.
|
static void |
log(java.lang.Object component,
int category,
java.lang.String message,
int value)
Logs a message and an integer value in the specified category for the
specified component.
|
static void |
log(java.lang.Object component,
int category,
java.lang.String message,
java.lang.Throwable e)
Logs a message in the specified category for the specified component.
|
static void |
log(java.lang.Object component,
int category,
java.lang.Throwable e)
Logs a message in the specified category for the specified component.
|
static void |
main(java.lang.String[] args)
Update trace parameters.
|
void |
run()
Listens for trace status changes.
|
static void |
setFileName(java.lang.Object component,
java.lang.String fileName)
Sets the trace file name for the specified component.
|
static void |
setFileName(java.lang.String fileName)
Sets the trace file name.
|
static void |
setPrintWriter(java.lang.Object component,
java.io.PrintWriter obj)
Sets the PrintWriter object for the specified component.
|
static void |
setPrintWriter(java.io.PrintWriter obj)
Sets the PrintWriter object.
|
static void |
setTraceAllOn(boolean traceAll)
Sets tracing for all categories on or off.
|
static void |
setTraceConversionOn(boolean traceConversion)
Sets character set conversion tracing on or off.
|
static void |
setTraceDatastreamOn(boolean traceDatastream)
Sets data stream tracing on or off.
|
static void |
setTraceDiagnosticOn(boolean traceDiagnostic)
Sets diagnostic tracing on or off.
|
static void |
setTraceErrorOn(boolean traceError)
Sets error tracing on or off.
|
static void |
setTraceInformationOn(boolean traceInformation)
Sets information tracing on or off.
|
static void |
setTraceJDBCOn(boolean traceJDBC)
Sets JDBC tracing on or off.
|
static void |
setTraceOn(boolean traceOn)
Sets tracing on or off.
|
static void |
setTracePCMLOn(boolean tracePCML)
Sets PCML tracing on or off.
|
static void |
setTraceProxyOn(boolean traceProxy)
Sets proxy stream tracing on or off.
|
static void |
setTraceThreadOn(boolean traceThread)
Sets thread tracing on or off.
|
static void |
setTraceWarningOn(boolean traceWarning)
Sets warning tracing on or off.
|
static java.lang.String |
toAsciiString(byte b)
Returns a string representation of the byte argument, as 1 ascii digits.
|
static java.lang.String |
toEbcdicString(byte b)
Returns a string representation of the byte argument, as 1 ebcdic digits.
|
static java.lang.String |
toHexString(byte b)
Returns a string representation of the byte argument, as 2 hexadecimal digits.
|
static java.lang.String |
toHexString(byte[] bytes)
Returns a string representation of the byte-array argument, as a sequence of hexadecimal digits.
|
public static final int DATASTREAM
public static final int DIAGNOSTIC
public static final int ERROR
public static final int INFORMATION
public static final int WARNING
public static final int CONVERSION
public static final int PROXY
public static final int PCML
public static final int JDBC
DriverManager
class.public static final java.lang.String LOGGER_NAME
public static java.lang.String getFileName()
public static java.lang.String getFileName(java.lang.Object component)
component
- public static java.io.PrintWriter getPrintWriter()
public static java.io.PrintWriter getPrintWriter(java.lang.Object component)
component
- public static final boolean isTraceAllOn()
public static final boolean isTraceConversionOn()
public static final boolean isTraceDatastreamOn()
public static final boolean isTraceDiagnosticOn()
public static final boolean isTraceErrorOn()
public static final boolean isTraceInformationOn()
public static final boolean isTraceJDBCOn()
public static final boolean isTraceOn()
public static final boolean isTraceOn(int category)
category
- The message category [DATASTREAM, DIAGNOSTIC,
ERROR, INFORMATION, WARNING, CONVERSION, PROXY, JDBC].public static final boolean isTracePCMLOn()
public static final boolean isTraceProxyOn()
public static final boolean isTraceThreadOn()
public static final boolean isTraceWarningOn()
public static final void log(int category, java.lang.String message)
category
- The message category [DATASTREAM, DIAGNOSTIC,
ERROR, INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.public static final void log(int category, java.lang.Object source, java.lang.String message)
category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR, INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.source
- Object that is posting this message.public static final void log(java.lang.Object component, int category, java.lang.String message)
component
- The component to trace.category
- The message category [DATASTREAM, DIAGNOSTIC,
ERROR, INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.public static final void log(java.lang.Object component, int category, java.lang.Object source, java.lang.String message)
component
- The component to trace.category
- The message category [DATASTREAM, DIAGNOSTIC,
ERROR, INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.source
- The object posting this message.public static final void log(int category, java.lang.String message, java.lang.Throwable e)
category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR, INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.e
- The Throwable object that contains the stack trace to log.public static final void log(int category, java.lang.Object source, java.lang.String message, java.lang.Throwable e)
category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR, INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.e
- The Throwable object that contains the stack trace to log.source
- The object posting this message.public static final void log(java.lang.Object component, int category, java.lang.String message, java.lang.Throwable e)
component
- The component to trace.category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR,
INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.e
- The Throwable object that contains the stack trace to log.public static final void log(int category, java.lang.Throwable e)
category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR,
INFORMATION, WARNING, CONVERSION, PROXY, JDBC].e
- The Throwable object that contains the stack trace to log.public static final void log(java.lang.Object component, int category, java.lang.Throwable e)
component
- The component to trace.category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR,
INFORMATION, WARNING, CONVERSION, PROXY, JDBC].e
- The Throwable object that contains the stack trace to log.public static final void log(int category, java.lang.String message, int value)
category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR,
INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.value
- The integer value to log.public static final void log(int category, java.lang.Object source, java.lang.String message, int value)
category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR,
INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.value
- The integer value to log.source
- The object posting this message.public static final void log(int category, java.lang.String message, java.lang.String value)
category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR,
INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.value
- The String value to log.public static final void log(java.lang.Object component, int category, java.lang.String message, int value)
component
- The component to trace.category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR,
INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.value
- The integer value to log.public static final void log(int category, java.lang.String message, boolean value)
category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR,
INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.value
- The boolean data to log.public static final void log(int category, java.lang.Object source, java.lang.String message, boolean value)
category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR,
INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.value
- The boolean data to log.source
- The object posting this message.public static final void log(java.lang.Object component, int category, java.lang.String message, boolean value)
component
- The component to trace.category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR,
INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.value
- The boolean data to log.public static final void log(int category, java.lang.String message, byte[] data)
category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR, INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.data
- The bytes to log.public static final void log(int category, java.lang.Object source, java.lang.String message, byte[] data)
category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR, INFORMATION, WARNING, CONVERSION, PROXY, JDBC].source
- message
- The message to log.data
- The bytes to log.public static final void log(java.lang.Object component, int category, java.lang.String message, byte[] data)
component
- The component to trace.category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR,
INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.data
- The bytes to log.public static final void log(int category, java.lang.String message, byte[] data, int offset, int length)
category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR,
INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.data
- The bytes to log.offset
- The start offset in the data.length
- The number of bytes of data to log.public static final void log(java.lang.Object component, int category, java.lang.String message, byte[] data, int offset, int length)
component
- The component to trace.category
- The message category [DATASTREAM, DIAGNOSTIC, ERROR,
INFORMATION, WARNING, CONVERSION, PROXY, JDBC].message
- The message to log.data
- The bytes to log.offset
- The start offset in the data.length
- The number of bytes of data to log.public static final java.lang.String toHexString(byte b)
b
- A byte to be converted to a string.public static final java.lang.String toAsciiString(byte b)
b
- A byte to be converted to a string.public static final java.lang.String toEbcdicString(byte b)
b
- A byte to be converted to a string.public static final java.lang.String toHexString(byte[] bytes)
bytes
- A byte array to be converted to a string.public static void setTraceAllOn(boolean traceAll)
traceAll
- If true, tracing for each category is on;
otherwise, tracing for each category is off.setTraceOn(boolean)
public static void setTraceConversionOn(boolean traceConversion)
traceConversion
- If true, conversion tracing is on;
otherwise, conversion tracing is off.setTraceOn(boolean)
public static void setTraceDatastreamOn(boolean traceDatastream)
traceDatastream
- If true, data stream tracing is on;
otherwise, data stream tracing is off.setTraceOn(boolean)
public static void setTraceDiagnosticOn(boolean traceDiagnostic)
traceDiagnostic
- If true, diagnostic tracing is on;
otherwise, diagnostic tracing is off.setTraceOn(boolean)
public static void setTraceErrorOn(boolean traceError)
traceError
- If true, error tracing is on; otherwise,
error tracing is off.setTraceOn(boolean)
public static void setFileName(java.lang.String fileName) throws java.io.IOException
fileName
- The log file name. If this is null, output goes to System.out.java.io.IOException
- If an error occurs while accessing the file.setPrintWriter(PrintWriter)
public static void setFileName(java.lang.Object component, java.lang.String fileName) throws java.io.IOException
fileName
- The log file name. If this is null, output goes to System.out.component
- The component to trace to the file.java.io.IOException
- If an error occurs while accessing the file.setPrintWriter(Object,PrintWriter)
public static void setPrintWriter(java.io.PrintWriter obj) throws java.io.IOException
obj
- The PrintWriter object. If this is null, output goes to System.out.
Note: The PrintWriter class has no relationship with IBM i "printer devices".java.io.IOException
- If an error occurs while accessing the file.setFileName(String)
public static void setPrintWriter(java.lang.Object component, java.io.PrintWriter obj) throws java.io.IOException
component
- The component to trace to the writer.obj
- The PrintWriter object. If this is null, output goes to System.out.
Note: The PrintWriter class has no relationship with IBM i "printer devices".java.io.IOException
- If an error occurs while accessing the file.setFileName(Object,String)
public static void setTraceInformationOn(boolean traceInformation)
traceInformation
- If true, information tracing is on;
otherwise, information tracing is off.setTraceOn(boolean)
public static void setTraceJDBCOn(boolean traceJDBC)
traceJDBC
- true to turn on JDBC tracing; false to turn it off.DriverManager
public static void setTraceOn(boolean traceOn)
traceOn
- If true, tracing is on; otherwise, all tracing is disabled.public static void setTracePCMLOn(boolean tracePCML)
tracePCML
- If true, PCML tracing is on; otherwise,
PCML tracing is off.public static void setTraceProxyOn(boolean traceProxy)
traceProxy
- If true, proxy tracing is on;
otherwise, proxy tracing is off.setTraceOn(boolean)
public static void setTraceThreadOn(boolean traceThread)
traceThread
- If true, thread tracing is on;
otherwise, thread tracing is off.setTraceOn(boolean)
public static void setTraceWarningOn(boolean traceWarning)
traceWarning
- If true, warning tracing is enabled;
otherwise, warning tracing is disabled.setTraceOn(boolean)
public void run()
run
in interface java.lang.Runnable
public static void main(java.lang.String[] args)
args
-