TraceImplementationpublic class TraceImplementation extends Object implements TraceDestinationExample implementation of the {@link TraceDestination} interface.
This implementation sends log records to a file (specified by the value of the
com.sun.jmx.trace.file system property) or to the system
console if no file is specified.
The log level is specified by the value of system property
com.sun.jmx.trace.level , which can be : DEBUG ,
TRACE , ERROR . If no trace level is specified, the
default is ERROR .
Note that this implementation does not provide any filtering based on the log
types. More precisely, the implementation of method {@link #isSelected} only
checks the provided log level. |
Fields Summary |
---|
private PrintWriter | out | private int | level |
Constructors Summary |
---|
public TraceImplementation()Constructor.
String filename;
if ((filename = System.getProperty("com.sun.jmx.trace.file")) != null)
{
// Output sent to the specified log file
//
this.out = new PrintWriter(new FileOutputStream(filename), true);
}
else
{
// Output sent to the system console
//
this.out = new PrintWriter(System.err, true);
}
String level;
if ((level = System.getProperty("com.sun.jmx.trace.level")) != null)
{
// Read log level from value of system property
//
if (level.equals("DEBUG"))
{
this.level = TraceTags.LEVEL_DEBUG;
}
else if (level.equals("TRACE"))
{
this.level = TraceTags.LEVEL_TRACE;
}
else
{
this.level = TraceTags.LEVEL_ERROR;
}
}
else
{
// Log level defaults to ERROR
//
this.level = TraceTags.LEVEL_ERROR;
}
|
Methods Summary |
---|
private static java.lang.String | getLevel(int level)Return the string representation of a trace level, as defined in
{@link TraceTags}
switch (level) {
case TraceTags.LEVEL_ERROR:
return "LEVEL_ERROR";
case TraceTags.LEVEL_TRACE:
return "LEVEL_TRACE";
case TraceTags.LEVEL_DEBUG:
return "LEVEL_DEBUG";
default :
return "UNKNOWN_TRACE_LEVEL";
}
| private static java.lang.String | getType(int type)Return the string representation of a trace type, as defined in
{@link TraceTags}
switch (type) {
case TraceTags.INFO_MBEANSERVER:
return "INFO_MBEANSERVER";
case TraceTags.INFO_ADAPTOR_SNMP:
return "INFO_ADAPTOR_SNMP";
case TraceTags.INFO_SNMP:
return "INFO_SNMP";
case TraceTags.INFO_MLET:
return "INFO_MLET";
case TraceTags.INFO_MONITOR:
return "INFO_MONITOR";
case TraceTags.INFO_TIMER:
return "INFO_TIMER";
case TraceTags.INFO_MISC:
return "INFO_MISC";
case TraceTags.INFO_NOTIFICATION:
return "INFO_NOTIFICATION";
case TraceTags.INFO_RELATION:
return "INFO_RELATION";
case TraceTags.INFO_MODELMBEAN:
return "INFO_MODELMBEAN";
default:
return "UNKNOWN_TRACE_TYPE";
}
| public static void | init()Registers a new instance of class {@link TraceImplementation} as the
trace destination in class {@link Trace}.
Trace.setDestination(new TraceImplementation());
| public static void | init(int level)Registers a new instance of class {@link TraceImplementation} as the
trace destination in class {@link Trace}.
final TraceImplementation impl = new TraceImplementation();
impl.level = level;
Trace.setDestination(impl);
| public boolean | isSelected(int level, int type)Only tests whether the provided log level will generate some output if
used as an argument to {@link #send(int, int, String, String, Throwable)}
or {@link #send(int, int, String, String, String)}
return (level <= this.level);
| static com.sun.jmx.trace.TraceImplementation | newDestination(int level)
try {
final TraceImplementation impl = new TraceImplementation();
impl.level = level;
return impl;
} catch (IOException x) {
return null;
}
| public void | reset()Not implemented.
| public boolean | send(int level, int type, java.lang.String className, java.lang.String methodName, java.lang.String info)
if (isSelected(level, type))
{
out.println(((className!=null)?"Class: " + className:"")+
((methodName!=null)?"\nMethod: " + methodName:"") +
"\n\tlevel: " + getLevel(level) +
"\n\ttype: " + getType(type) +
"\n\tmessage: " + info);
//out.flush();
return true;
}
return false;
| public boolean | send(int level, int type, java.lang.String className, java.lang.String methodName, java.lang.Throwable exception)
final boolean result = send(level, type, className, methodName,
exception.toString());
if (result)
exception.printStackTrace(out);
return result;
|
|