Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2010-04-01 21:29:50 +0000
committerThomas Watson2010-04-01 21:29:50 +0000
commit45fad02a992a4e0f6e6eae32a7a177b82da74878 (patch)
tree0b6eeb539c534159817eaed87ea994aa771dd358 /bundles
parent34b7661bb9a91196ef9523005686277d1824a242 (diff)
downloadrt.equinox.framework-45fad02a992a4e0f6e6eae32a7a177b82da74878.tar.gz
rt.equinox.framework-45fad02a992a4e0f6e6eae32a7a177b82da74878.tar.xz
rt.equinox.framework-45fad02a992a4e0f6e6eae32a7a177b82da74878.zip
Bug 267683 - Enhancements to the tracing framework
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/debugoptions/DebugOptionsTestCase.java178
-rw-r--r--bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/EclipseDebugTrace.java110
-rw-r--r--bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugOptions.java25
-rw-r--r--bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugTraceEntry.java13
4 files changed, 253 insertions, 73 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/debugoptions/DebugOptionsTestCase.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/debugoptions/DebugOptionsTestCase.java
index 7490c0f69..c3a6b33ac 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/debugoptions/DebugOptionsTestCase.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/debugoptions/DebugOptionsTestCase.java
@@ -19,6 +19,7 @@ import java.util.Map.Entry;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.core.tests.harness.CoreTest;
+import org.eclipse.osgi.framework.debug.FrameworkDebugOptions;
import org.eclipse.osgi.framework.debug.FrameworkDebugTraceEntry;
import org.eclipse.osgi.service.debug.*;
import org.eclipse.osgi.tests.OSGiTestsActivator;
@@ -39,6 +40,7 @@ public class DebugOptionsTestCase extends CoreTest {
private final static String TRACE_ELEMENT_DELIMITER_ENCODED = "|"; //$NON-NLS-1$ // this value needs to match EclipseDebugTrace#TRACE_ELEMENT_DELIMITER_ENCODED
private final static SimpleDateFormat TRACE_FILE_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); //$NON-NLS-1$
private final static String LINE_SEPARATOR;
+ private boolean verboseDebug = true; // default is true
static {
String s = System.getProperty("line.separator"); //$NON-NLS-1$
LINE_SEPARATOR = s == null ? "\n" : s; //$NON-NLS-1$
@@ -493,6 +495,101 @@ public class DebugOptionsTestCase extends CoreTest {
}
/**
+ * Test all DebugTrace.trace*() API when verbose debugging is disabled
+ */
+ public void testVerboseDebugging() {
+
+ // TODO: Convert this back to {@link DebugOptions} once is/setVerbose becomes API
+ FrameworkDebugOptions fwDebugOptions = (FrameworkDebugOptions) debugOptions;
+ if (!debugOptions.isDebugEnabled()) {
+ debugOptions.setDebugEnabled(true);
+ }
+ // create a tracing record
+ final File traceFile = OSGiTestsActivator.getContext().getDataFile(getName() + ".trace"); //$NON-NLS-1$
+ TestDebugTrace debugTrace = this.createDebugTrace(traceFile);
+ TraceEntry[] traceOutput = null;
+ final String exceptionMessage1 = "An error 1"; //$NON-NLS-1$
+ try {
+ fwDebugOptions.setVerbose(false);
+ debugTrace.trace("/debug", "testing 1", new Exception(exceptionMessage1)); //$NON-NLS-1$ //$NON-NLS-2$
+ fwDebugOptions.setVerbose(true);
+ debugTrace.trace("/debug", "testing 2"); //$NON-NLS-1$ //$NON-NLS-2$
+ fwDebugOptions.setVerbose(false);
+ debugTrace.trace("/debug", "testing 3"); //$NON-NLS-1$ //$NON-NLS-2$
+ debugTrace.traceEntry("/debug"); //$NON-NLS-1$ //$NON-NLS-2$
+ debugTrace.traceEntry("/debug", "arg"); //$NON-NLS-1$ //$NON-NLS-2$
+ debugTrace.traceEntry("/debug", new String[] {"arg1", "arg2"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ debugTrace.traceExit("/debug"); //$NON-NLS-1$
+ debugTrace.traceExit("/debug", "returnValue"); //$NON-NLS-1$ //$NON-NLS-2$
+ traceOutput = readTraceFile(traceFile); // Note: this call will also delete the trace file
+ } catch (InvalidTraceEntry invalidEx) {
+ fail("Failed 'DebugTrace.trace(option, message)' test as an invalid trace entry was found. Actual Value: '" + invalidEx.getActualValue() + "'.", invalidEx); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ // make sure all 3 entries exist
+ assertEquals("Wrong number of trace entries", 8, traceOutput.length); //$NON-NLS-1$
+ // validate the trace("/debug", "testing 1", new Exception(exceptionMessage1)) call when verbose tracing is disabled
+ assertEquals("Thread name is incorrect", Thread.currentThread().getName(), traceOutput[0].getThreadName()); //$NON-NLS-1$
+ assertNull("A bundle was found when it should be null", traceOutput[0].getBundleSymbolicName()); //$NON-NLS-1$
+ assertNull("A class name was found when it should be null", traceOutput[0].getClassName()); //$NON-NLS-1$
+ assertNull("A method name was found when it should be null", traceOutput[0].getMethodName()); //$NON-NLS-1$
+ assertTrue("A line number other than -1 was read in", traceOutput[0].getLineNumber() == -1); //$NON-NLS-1$
+ assertEquals("trace message is incorrect", "testing 1", traceOutput[0].getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ final StringBuffer expectedThrowableText1 = new StringBuffer("java.lang.Exception: "); //$NON-NLS-1$
+ expectedThrowableText1.append(exceptionMessage1);
+ expectedThrowableText1.append(DebugOptionsTestCase.LINE_SEPARATOR);
+ expectedThrowableText1.append(DebugOptionsTestCase.TAB_CHARACTER);
+ expectedThrowableText1.append("at org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase.testVerboseDebugging(DebugOptionsTestCase.java:"); //$NON-NLS-1$
+ if (!traceOutput[0].getThrowableText().startsWith(expectedThrowableText1.toString())) {
+ final StringBuffer errorMessage = new StringBuffer("The expected throwable text does not start with the actual throwable text."); //$NON-NLS-1$
+ errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
+ errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
+ errorMessage.append("Expected"); //$NON-NLS-1$
+ errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
+ errorMessage.append("--------"); //$NON-NLS-1$
+ errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
+ errorMessage.append(expectedThrowableText1.toString());
+ errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
+ errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
+ errorMessage.append("Actual"); //$NON-NLS-1$
+ errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
+ errorMessage.append("--------"); //$NON-NLS-1$
+ errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
+ errorMessage.append(traceOutput[0].getThrowableText());
+ fail(errorMessage.toString());
+ }
+ // validate the trace("/debug", "testing 2") call when verbose tracing is re-enabled
+ assertEquals("Thread name is incorrect", Thread.currentThread().getName(), traceOutput[1].getThreadName()); //$NON-NLS-1$
+ assertEquals("Bundle name is incorrect", getName(), traceOutput[1].getBundleSymbolicName()); //$NON-NLS-1$
+ assertEquals("option-path value is incorrect", "/debug", traceOutput[1].getOptionPath()); //$NON-NLS-1$//$NON-NLS-2$
+ assertEquals("class name value is incorrect", DebugOptionsTestCase.class.getName(), traceOutput[1].getClassName()); //$NON-NLS-1$
+ assertEquals("method name value is incorrect", "testVerboseDebugging", traceOutput[1].getMethodName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("trace message is incorrect", "testing 2", traceOutput[1].getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertNull("The throwable text was found when it should be null", traceOutput[1].getThrowableText());
+ // validate the trace("/debug", "testing 3") call when verbose is disabled
+ assertEquals("Thread name is incorrect", Thread.currentThread().getName(), traceOutput[2].getThreadName()); //$NON-NLS-1$
+ assertNull("A bundle was found when it should be null", traceOutput[2].getBundleSymbolicName()); //$NON-NLS-1$
+ assertNull("A class name was found when it should be null", traceOutput[2].getClassName()); //$NON-NLS-1$
+ assertNull("A method name was found when it should be null", traceOutput[2].getMethodName()); //$NON-NLS-1$
+ assertTrue("A line number other than -1 was read in", traceOutput[2].getLineNumber() == -1); //$NON-NLS-1$
+ assertEquals("trace message is incorrect", "testing 3", traceOutput[2].getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertNull("The throwable text was found when it should be null", traceOutput[2].getThrowableText());
+ // validate the traceEntry("/debug") call when verbose is disabled
+ assertEquals("trace message is incorrect", "Entering method org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase#testVerboseDebugging with no parameters", traceOutput[3].getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ // validate the traceEntry("/debug", "arg") call when verbose is disabled
+ assertEquals("trace message is incorrect", "Entering method org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase#testVerboseDebugging with parameters: (arg)", traceOutput[4].getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ // validate the traceEntry("/debug", new String[] {"arg1", "arg2"}) call when verbose is disabled
+ assertEquals("trace message is incorrect", "Entering method org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase#testVerboseDebugging with parameters: (arg1 arg2)", traceOutput[5].getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ // validate the traceExit("/debug") call when verbose is disabled
+ assertEquals("trace message is incorrect", "Exiting method org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase#testVerboseDebugging with a void return", traceOutput[6].getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ // validate the traceExit("/debug", "returnValue") call when verbose is disabled
+ assertEquals("trace message is incorrect", "Exiting method org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase#testVerboseDebugging with result: returnValue", traceOutput[7].getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ // make sure the file is deleted
+ traceFile.delete();
+ // reset verbose debugging to the default (true)
+ fwDebugOptions.setVerbose(true);
+ }
+
+ /**
* test DebugTrace.trace(option, message);
*/
public void testTraceFile01() {
@@ -878,8 +975,9 @@ public class DebugOptionsTestCase extends CoreTest {
private TraceEntry[] readTraceFile(File traceFile) throws InvalidTraceEntry {
- Reader traceReader = null;
+ BufferedReader traceReader = null;
List traceEntries = new ArrayList();
+ this.verboseDebug = true; // default is true
try {
traceReader = new BufferedReader(new InputStreamReader(new FileInputStream(traceFile), "UTF-8")); //$NON-NLS-1$
TraceEntry entry = null;
@@ -900,25 +998,30 @@ public class DebugOptionsTestCase extends CoreTest {
return (TraceEntry[]) traceEntries.toArray(new TraceEntry[traceEntries.size()]);
}
- private TraceEntry readMessage(final Reader traceReader) throws IOException, InvalidTraceEntry {
+ private TraceEntry readMessage(final BufferedReader traceReader) throws IOException, InvalidTraceEntry {
TraceEntry result = null;
int input = traceReader.read();
while (input != -1) {
char inputChar = (char) input;
if (inputChar == '#') {
- while ((inputChar != '\n') && (inputChar != '\r')) {
- // do nothing
- inputChar = (char) traceReader.read();
+ String comment = traceReader.readLine();
+ if (comment != null) {
+ comment = comment.trim();
+ }
+ if (comment.startsWith("verbose")) {
+ int splitIndex = comment.indexOf(':');
+ String verboseValue = comment.substring(splitIndex + 1, comment.length()).trim();
+ this.verboseDebug = Boolean.valueOf(verboseValue).booleanValue();
}
}
if (inputChar == DebugOptionsTestCase.TRACE_ELEMENT_DELIMITER.charAt(0)) {
- // first entry - thread name
+ // first entry - thread name (valid if verbose debugging is off)
final String threadName = this.readEntry(traceReader);
if ((threadName == null) || (threadName.length() == 0)) {
throw new InvalidTraceEntry("The thread name in a trace entry is null or empty", threadName); //$NON-NLS-1$
}
- // read the next character
+ // second entry - timestamp (valid if verbose debugging is off)
final String date = this.readEntry(traceReader);
if ((date == null) || (date.length() == 0)) {
throw new InvalidTraceEntry("The timestamp in a trace entry is null or empty", date); //$NON-NLS-1$
@@ -929,35 +1032,42 @@ public class DebugOptionsTestCase extends CoreTest {
} catch (ParseException parseEx) {
throw new InvalidTraceEntry("The date in a trace entry '" + date + "' could not be parsed.", date); //$NON-NLS-1$ //$NON-NLS-2$
}
- // third entry - bundle symbolic name
- final String symbolicName = this.readEntry(traceReader);
- if ((symbolicName == null) || (symbolicName.length() == 0)) {
- throw new InvalidTraceEntry("The bundle symbolic name in a trace entry is null or empty", symbolicName); //$NON-NLS-1$
- }
- // fourth entry - option path
- final String optionPath = this.readEntry(traceReader);
- if ((optionPath == null) || (optionPath.length() == 0)) {
- throw new InvalidTraceEntry("The option-path in a trace entry is null or empty", optionPath); //$NON-NLS-1$
- }
- // fifth entry - class name
- final String className = this.readEntry(traceReader);
- if ((className == null) || (className.length() == 0)) {
- throw new InvalidTraceEntry("The class name in a trace entry is null or empty", className); //$NON-NLS-1$
- }
- // sixth entry - method name
- final String methodName = this.readEntry(traceReader);
- if ((methodName == null) || (methodName.length() == 0)) {
- throw new InvalidTraceEntry("The method name in a trace entry is null or empty", methodName); //$NON-NLS-1$
- }
- // seventh entry - line number
- final String lineNumberString = this.readEntry(traceReader);
- if ((lineNumberString == null) || (lineNumberString.length() == 0)) {
- throw new InvalidTraceEntry("The line number in a trace entry is null or empty", lineNumberString); //$NON-NLS-1$
+ String symbolicName = null;
+ String optionPath = null;
+ String className = null;
+ String methodName = null;
+ int lineNumber = -1;
+ if (this.verboseDebug) {
+ // third entry - bundle symbolic name
+ symbolicName = this.readEntry(traceReader);
+ if ((symbolicName == null) || (symbolicName.length() == 0)) {
+ throw new InvalidTraceEntry("The bundle symbolic name in a trace entry is null or empty", symbolicName); //$NON-NLS-1$
+ }
+ // fourth entry - option path
+ optionPath = this.readEntry(traceReader);
+ if ((optionPath == null) || (optionPath.length() == 0)) {
+ throw new InvalidTraceEntry("The option-path in a trace entry is null or empty", optionPath); //$NON-NLS-1$
+ }
+ // fifth entry - class name
+ className = this.readEntry(traceReader);
+ if ((className == null) || (className.length() == 0)) {
+ throw new InvalidTraceEntry("The class name in a trace entry is null or empty", className); //$NON-NLS-1$
+ }
+ // sixth entry - method name
+ methodName = this.readEntry(traceReader);
+ if ((methodName == null) || (methodName.length() == 0)) {
+ throw new InvalidTraceEntry("The method name in a trace entry is null or empty", methodName); //$NON-NLS-1$
+ }
+ // seventh entry - line number
+ final String lineNumberString = this.readEntry(traceReader);
+ if ((lineNumberString == null) || (lineNumberString.length() == 0)) {
+ throw new InvalidTraceEntry("The line number in a trace entry is null or empty", lineNumberString); //$NON-NLS-1$
+ }
+ lineNumber = Integer.valueOf(lineNumberString).intValue();
}
- final int lineNumber = Integer.valueOf(lineNumberString).intValue();
- // eighth entry - message
+ // eighth entry - message (valid if verbose debugging is off)
final String message = this.readEntry(traceReader);
- // read in the next character. if it is \r or \n then the throwable was not supplied
+ // read in the next character. if it is \r or \n then the throwable was not supplied (valid if verbose debugging is off)
traceReader.mark(1);
inputChar = (char) traceReader.read();
String throwable = null;
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/EclipseDebugTrace.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/EclipseDebugTrace.java
index 1d0d5ba0e..b1f89c984 100644
--- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/EclipseDebugTrace.java
+++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/EclipseDebugTrace.java
@@ -12,10 +12,10 @@ package org.eclipse.osgi.framework.debug;
import java.io.*;
import java.security.AccessController;
+import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.eclipse.osgi.framework.util.SecureAction;
-import org.eclipse.osgi.service.debug.DebugOptions;
import org.eclipse.osgi.service.debug.DebugTrace;
/**
@@ -30,16 +30,18 @@ class EclipseDebugTrace implements DebugTrace {
/** The trace message for a thread stack dump */
private final static String MESSAGE_THREAD_DUMP = "Thread Stack dump: "; //$NON-NLS-1$
/** The trace message for a method completing with a return value */
- private final static String MESSAGE_EXIT_METHOD_WITH_RESULTS = "Exiting method with result: "; //$NON-NLS-1$
+ private final static String MESSAGE_EXIT_METHOD_WITH_RESULTS = "Exiting method {0}with result: "; //$NON-NLS-1$
/** The trace message for a method completing with no return value */
- private final static String MESSAGE_EXIT_METHOD_NO_RESULTS = "Exiting method with a void return"; //$NON-NLS-1$
+ private final static String MESSAGE_EXIT_METHOD_NO_RESULTS = "Exiting method {0}with a void return"; //$NON-NLS-1$
/** The trace message for a method starting with a set of arguments */
- private final static String MESSAGE_ENTER_METHOD_WITH_PARAMS = "Entering method with parameters: ("; //$NON-NLS-1$
+ private final static String MESSAGE_ENTER_METHOD_WITH_PARAMS = "Entering method {0}with parameters: ("; //$NON-NLS-1$
/** The trace message for a method starting with no arguments */
- private final static String MESSAGE_ENTER_METHOD_NO_PARAMS = "Entering method with no parameters"; //$NON-NLS-1$
- /** The version attribute written to the header of the trace file */
+ private final static String MESSAGE_ENTER_METHOD_NO_PARAMS = "Entering method {0}with no parameters"; //$NON-NLS-1$
+ /** The version attribute written in the header of a new session */
private final static String TRACE_FILE_VERSION_COMMENT = "version: "; //$NON-NLS-1$
- /** The version value written to the header of the trace file */
+ /** The verbose attribute written in the header of a new session */
+ private final static String TRACE_FILE_VERBOSE_COMMENT = "verbose: "; //$NON-NLS-1$
+ /** The version value written in the header of a new session */
private final static String TRACE_FILE_VERSION = "1.1"; //$NON-NLS-1$
/** The new session identifier to be written whenever a new session starts */
private final static String TRACE_NEW_SESSION = "!SESSION "; //$NON-NLS-1$
@@ -93,7 +95,7 @@ class EclipseDebugTrace implements DebugTrace {
/** A flag to determine if the message being written is done to a new file (i.e. should the header information be written) */
static boolean newSession = true;
/** DebugOptions are used to determine if the specified bundle symbolic name + option-path has debugging enabled */
- private DebugOptions debugOptions = null;
+ private FrameworkDebugOptions debugOptions = null;
/**
* Construct a new EclipseDebugTrace for the specified bundle symbolic name and write messages to the specified
@@ -102,7 +104,7 @@ class EclipseDebugTrace implements DebugTrace {
* @param bundleSymbolicName The symbolic name of the bundle being traced
* @param debugOptions Used to determine if the specified bundle symbolic name + option-path has tracing enabled
*/
- public EclipseDebugTrace(final String bundleSymbolicName, final DebugOptions debugOptions) {
+ EclipseDebugTrace(final String bundleSymbolicName, final FrameworkDebugOptions debugOptions) {
this(bundleSymbolicName, debugOptions, null);
}
@@ -115,7 +117,7 @@ class EclipseDebugTrace implements DebugTrace {
* @param debugOptions Used to determine if the specified bundle symbolic name + option-path has tracing enabled
* @param traceClass The class that the client is using to perform trace API calls
*/
- public EclipseDebugTrace(final String bundleSymbolicName, final DebugOptions debugOptions, final Class traceClass) {
+ EclipseDebugTrace(final String bundleSymbolicName, final FrameworkDebugOptions debugOptions, final Class traceClass) {
this.traceClass = traceClass != null ? traceClass.getName() : null;
this.debugOptions = debugOptions;
@@ -171,7 +173,8 @@ class EclipseDebugTrace implements DebugTrace {
public void traceEntry(final String optionPath) {
if (isDebuggingEnabled(optionPath)) {
- final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, EclipseDebugTrace.MESSAGE_ENTER_METHOD_NO_PARAMS, traceClass);
+ final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, null, traceClass);
+ setMessage(record, EclipseDebugTrace.MESSAGE_ENTER_METHOD_NO_PARAMS);
writeRecord(record);
}
}
@@ -210,7 +213,8 @@ class EclipseDebugTrace implements DebugTrace {
}
messageBuffer.append(")"); //$NON-NLS-1$
}
- final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, messageBuffer.toString(), traceClass);
+ final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, null, traceClass);
+ setMessage(record, messageBuffer.toString());
writeRecord(record);
}
}
@@ -222,7 +226,8 @@ class EclipseDebugTrace implements DebugTrace {
public void traceExit(final String optionPath) {
if (isDebuggingEnabled(optionPath)) {
- final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, EclipseDebugTrace.MESSAGE_EXIT_METHOD_NO_RESULTS, traceClass);
+ final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, null, traceClass);
+ setMessage(record, EclipseDebugTrace.MESSAGE_EXIT_METHOD_NO_RESULTS);
writeRecord(record);
}
}
@@ -240,7 +245,8 @@ class EclipseDebugTrace implements DebugTrace {
} else {
messageBuffer.append(result.toString());
}
- final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, messageBuffer.toString(), traceClass);
+ final FrameworkDebugTraceEntry record = new FrameworkDebugTraceEntry(bundleSymbolicName, optionPath, null, traceClass);
+ setMessage(record, messageBuffer.toString());
writeRecord(record);
}
}
@@ -273,6 +279,29 @@ class EclipseDebugTrace implements DebugTrace {
}
/**
+ * Set the trace message for the specified record to include class and method information
+ * if verbose debugging is disabled.
+ *
+ * @param record The {@link FrameworkDebugTraceEntry} containing the information to persist to the trace file.
+ * @param originalMessage The original tracing message
+ */
+ private final void setMessage(final FrameworkDebugTraceEntry record, final String originalMessage) {
+
+ String argument = null;
+ if (!debugOptions.isVerbose()) {
+ final StringBuffer classMethodName = new StringBuffer(record.getClassName());
+ classMethodName.append("#"); //$NON-NLS-1$
+ classMethodName.append(record.getMethodName());
+ classMethodName.append(" "); //$NON-NLS-1$
+ argument = classMethodName.toString();
+ } else {
+ argument = ""; //$NON-NLS-1$
+ }
+ String newMessage = MessageFormat.format(originalMessage, new Object[] {argument});
+ record.setMessage(newMessage);
+ }
+
+ /**
* Utility method to convert an array of StackTraceElement objects to form a String representation of a stack dump
*
* @param elements
@@ -412,6 +441,7 @@ class EclipseDebugTrace implements DebugTrace {
traceWriter = openWriter(traceFile);
writeComment(traceWriter, "This is a continuation of trace file " + backupFile.getAbsolutePath()); //$NON-NLS-1$
writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_VERSION_COMMENT + EclipseDebugTrace.TRACE_FILE_VERSION);
+ writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_VERBOSE_COMMENT + debugOptions.isVerbose());
writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_DATE + getFormattedDate(timestamp));
traceWriter.flush();
} catch (IOException ioEx) {
@@ -491,6 +521,7 @@ class EclipseDebugTrace implements DebugTrace {
writeComment(traceWriter, EclipseDebugTrace.TRACE_NEW_SESSION + this.getFormattedDate(timestamp));
writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_VERSION_COMMENT + EclipseDebugTrace.TRACE_FILE_VERSION);
+ writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_VERBOSE_COMMENT + debugOptions.isVerbose());
writeComment(traceWriter, "The following option strings are specified for this debug session:"); //$NON-NLS-1$
final String[] allOptions = FrameworkDebugOptions.getDefault().getAllOptions();
for (int i = 0; i < allOptions.length; i++) {
@@ -509,8 +540,7 @@ class EclipseDebugTrace implements DebugTrace {
*/
private void writeMessage(final Writer traceWriter, final FrameworkDebugTraceEntry entry) throws IOException {
- // format the trace entry
- StringBuffer message = new StringBuffer(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER);
+ final StringBuffer message = new StringBuffer(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER);
message.append(" "); //$NON-NLS-1$
message.append(encodeText(entry.getThreadName()));
message.append(" "); //$NON-NLS-1$
@@ -520,27 +550,33 @@ class EclipseDebugTrace implements DebugTrace {
message.append(" "); //$NON-NLS-1$
message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER);
message.append(" "); //$NON-NLS-1$
- message.append(entry.getBundleSymbolicName());
- message.append(" "); //$NON-NLS-1$
- message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER);
- message.append(" "); //$NON-NLS-1$
- message.append(encodeText(entry.getOptionPath()));
- message.append(" "); //$NON-NLS-1$
- message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER);
- message.append(" "); //$NON-NLS-1$
- message.append(entry.getClassName());
- message.append(" "); //$NON-NLS-1$
- message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER);
- message.append(" "); //$NON-NLS-1$
- message.append(entry.getMethodName());
- message.append(" "); //$NON-NLS-1$
- message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER);
- message.append(" "); //$NON-NLS-1$
- message.append(entry.getLineNumber());
- message.append(" "); //$NON-NLS-1$
- message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER);
- message.append(" "); //$NON-NLS-1$
- message.append(encodeText(entry.getMessage()));
+ if (!debugOptions.isVerbose()) {
+ // format the trace entry for quiet tracing: only the thread name, timestamp, trace message, and exception (if necessary)
+ message.append(encodeText(entry.getMessage()));
+ } else {
+ // format the trace entry for verbose tracing
+ message.append(entry.getBundleSymbolicName());
+ message.append(" "); //$NON-NLS-1$
+ message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER);
+ message.append(" "); //$NON-NLS-1$
+ message.append(encodeText(entry.getOptionPath()));
+ message.append(" "); //$NON-NLS-1$
+ message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER);
+ message.append(" "); //$NON-NLS-1$
+ message.append(entry.getClassName());
+ message.append(" "); //$NON-NLS-1$
+ message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER);
+ message.append(" "); //$NON-NLS-1$
+ message.append(entry.getMethodName());
+ message.append(" "); //$NON-NLS-1$
+ message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER);
+ message.append(" "); //$NON-NLS-1$
+ message.append(entry.getLineNumber());
+ message.append(" "); //$NON-NLS-1$
+ message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER);
+ message.append(" "); //$NON-NLS-1$
+ message.append(encodeText(entry.getMessage()));
+ }
if (entry.getThrowable() != null) {
message.append(" "); //$NON-NLS-1$
message.append(EclipseDebugTrace.TRACE_ELEMENT_DELIMITER);
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugOptions.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugOptions.java
index 020022dc8..445ad49f8 100644
--- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugOptions.java
+++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugOptions.java
@@ -31,6 +31,7 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer;
public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustomizer {
private static final String OSGI_DEBUG = "osgi.debug"; //$NON-NLS-1$
+ private static final String OSGI_DEBUG_VERBOSE = "osgi.debug.verbose"; //$NON-NLS-1$
public static final String PROP_TRACEFILE = "osgi.tracefile"; //$NON-NLS-1$
/** monitor used to lock the options maps */
private final Object lock = new Object();
@@ -46,6 +47,8 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom
protected final static Map debugTraceCache = new HashMap();
/** The File object to store messages. This value may be null. */
protected File outFile = null;
+ /** Is verbose debugging enabled? Changing this value causes a new tracing session to start. */
+ protected boolean verboseDebug = true;
private volatile BundleContext context;
private volatile ServiceTracker listenerTracker;
@@ -53,6 +56,8 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom
* Internal constructor to create a <code>FrameworkDebugOptions</code> singleton object.
*/
private FrameworkDebugOptions() {
+ // check if verbose debugging was set during initialization. This needs to be set even if debugging is disabled
+ this.verboseDebug = Boolean.valueOf(FrameworkProperties.getProperty(OSGI_DEBUG_VERBOSE, Boolean.TRUE.toString())).booleanValue();
// if no debug option was specified, don't even bother to try.
// Must ensure that the options slot is null as this is the signal to the
// platform that debugging is not enabled.
@@ -433,6 +438,26 @@ public class FrameworkDebugOptions implements DebugOptions, ServiceTrackerCustom
EclipseDebugTrace.newSession = true;
}
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.osgi.service.debug.DebugOptions#getVerbose()
+ */
+ boolean isVerbose() {
+
+ return this.verboseDebug;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.osgi.service.debug.DebugOptions#setVerbose(boolean)
+ */
+ public synchronized void setVerbose(final boolean verbose) {
+
+ this.verboseDebug = verbose;
+ // the verbose flag changed so start a new session
+ EclipseDebugTrace.newSession = true;
+ }
+
/**
* Notifies the trace listener for the specified bundle that its option-path has changed.
* @param bundleSymbolicName The bundle of the owning trace listener to notify.
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugTraceEntry.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugTraceEntry.java
index 4538324c0..0fca678b9 100644
--- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugTraceEntry.java
+++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/framework/debug/FrameworkDebugTraceEntry.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 IBM Corporation and others.
+ * Copyright (c) 2009, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -56,7 +56,7 @@ public class FrameworkDebugTraceEntry {
/**
* The trace message
*/
- private final String message;
+ private String message;
/**
* The trace exception
@@ -264,4 +264,13 @@ public class FrameworkDebugTraceEntry {
return lineNumber;
}
+
+ /**
+ *
+ * @param newMessage
+ */
+ void setMessage(final String newMessage) {
+
+ message = newMessage;
+ }
} \ No newline at end of file

Back to the top