|
Lines 20-101
Link Here
|
| 20 |
|
20 |
|
| 21 |
/** |
21 |
/** |
| 22 |
* The DebugTrace implementation for Eclipse. |
22 |
* The DebugTrace implementation for Eclipse. |
| 23 |
* <p> |
|
|
| 24 |
* Clients may extend this class. |
| 25 |
* </p> |
| 26 |
* @since 3.5 |
| 27 |
*/ |
23 |
*/ |
| 28 |
public class EclipseDebugTrace implements DebugTrace { |
24 |
class EclipseDebugTrace implements DebugTrace { |
| 29 |
|
25 |
|
| 30 |
/** The system property used to specify size a trace file can grow before it is rotated */ |
26 |
/** The system property used to specify size a trace file can grow before it is rotated */ |
| 31 |
public static final String PROP_TRACE_SIZE_MAX = "eclipse.trace.size.max"; //$NON-NLS-1$ |
27 |
private static final String PROP_TRACE_SIZE_MAX = "eclipse.trace.size.max"; //$NON-NLS-1$ |
| 32 |
/** The system property used to specify the maximum number of backup trace files to use */ |
28 |
/** The system property used to specify the maximum number of backup trace files to use */ |
| 33 |
public static final String PROP_TRACE_FILE_MAX = "eclipse.trace.backup.max"; //$NON-NLS-1$ |
29 |
private static final String PROP_TRACE_FILE_MAX = "eclipse.trace.backup.max"; //$NON-NLS-1$ |
| 34 |
/** The trace message for a thread stack dump */ |
30 |
/** The trace message for a thread stack dump */ |
| 35 |
protected final static String MESSAGE_THREAD_DUMP = "Thread Stack dump: "; //$NON-NLS-1$ |
31 |
private final static String MESSAGE_THREAD_DUMP = "Thread Stack dump: "; //$NON-NLS-1$ |
| 36 |
/** The trace message for a method completing with a return value */ |
32 |
/** The trace message for a method completing with a return value */ |
| 37 |
protected final static String MESSAGE_EXIT_METHOD_WITH_RESULTS = "Exiting method with result: "; //$NON-NLS-1$ |
33 |
private final static String MESSAGE_EXIT_METHOD_WITH_RESULTS = "Exiting method with result: "; //$NON-NLS-1$ |
| 38 |
/** The trace message for a method completing with no return value */ |
34 |
/** The trace message for a method completing with no return value */ |
| 39 |
protected final static String MESSAGE_EXIT_METHOD_NO_RESULTS = "Exiting method with a void return"; //$NON-NLS-1$ |
35 |
private final static String MESSAGE_EXIT_METHOD_NO_RESULTS = "Exiting method with a void return"; //$NON-NLS-1$ |
| 40 |
/** The trace message for a method starting with a set of arguments */ |
36 |
/** The trace message for a method starting with a set of arguments */ |
| 41 |
protected final static String MESSAGE_ENTER_METHOD_WITH_PARAMS = "Entering method with parameters: ("; //$NON-NLS-1$ |
37 |
private final static String MESSAGE_ENTER_METHOD_WITH_PARAMS = "Entering method with parameters: ("; //$NON-NLS-1$ |
| 42 |
/** The trace message for a method starting with no arguments */ |
38 |
/** The trace message for a method starting with no arguments */ |
| 43 |
protected final static String MESSAGE_ENTER_METHOD_NO_PARAMS = "Entering method with no parameters"; //$NON-NLS-1$ |
39 |
private final static String MESSAGE_ENTER_METHOD_NO_PARAMS = "Entering method with no parameters"; //$NON-NLS-1$ |
| 44 |
/** The version attribute written to the header of the trace file */ |
40 |
/** The version attribute written to the header of the trace file */ |
| 45 |
protected final static String TRACE_FILE_VERSION_COMMENT = "version: "; //$NON-NLS-1$ |
41 |
private final static String TRACE_FILE_VERSION_COMMENT = "version: "; //$NON-NLS-1$ |
| 46 |
/** The version value written to the header of the trace file */ |
42 |
/** The version value written to the header of the trace file */ |
| 47 |
protected final static String TRACE_FILE_VERSION = "1.0"; //$NON-NLS-1$ |
43 |
private final static String TRACE_FILE_VERSION = "1.0"; //$NON-NLS-1$ |
| 48 |
/** The new session identifier to be written whenever a new session starts */ |
44 |
/** The new session identifier to be written whenever a new session starts */ |
| 49 |
protected final static String TRACE_NEW_SESSION = "!SESSION "; //$NON-NLS-1$ |
45 |
private final static String TRACE_NEW_SESSION = "!SESSION "; //$NON-NLS-1$ |
| 50 |
/** The date attribute written to the header of the trace file to show when this file was created */ |
46 |
/** The date attribute written to the header of the trace file to show when this file was created */ |
| 51 |
protected final static String TRACE_FILE_DATE = "Time of creation: "; //$NON-NLS-1$ |
47 |
private final static String TRACE_FILE_DATE = "Time of creation: "; //$NON-NLS-1$ |
| 52 |
/** Trace date formatter using the pattern: yyyy-MM-dd HH:mm:ss.SSS */ |
48 |
/** Trace date formatter using the pattern: yyyy-MM-dd HH:mm:ss.SSS */ |
| 53 |
protected final static SimpleDateFormat TRACE_FILE_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); //$NON-NLS-1$ |
49 |
private final static SimpleDateFormat TRACE_FILE_DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); //$NON-NLS-1$ |
| 54 |
/** The comment character used by the trace file */ |
50 |
/** The comment character used by the trace file */ |
| 55 |
protected final static String TRACE_COMMENT = "#"; //$NON-NLS-1$ |
51 |
private final static String TRACE_COMMENT = "#"; //$NON-NLS-1$ |
| 56 |
/** The delimiter used to separate trace elements such as the time stamp, message, etc */ |
52 |
/** The delimiter used to separate trace elements such as the time stamp, message, etc */ |
| 57 |
protected final static String TRACE_ELEMENT_DELIMITER = "|"; //$NON-NLS-1$ |
53 |
private final static String TRACE_ELEMENT_DELIMITER = "|"; //$NON-NLS-1$ |
| 58 |
/** OS-specific line separator */ |
54 |
/** OS-specific line separator */ |
| 59 |
protected static final String LINE_SEPARATOR; |
55 |
private static final String LINE_SEPARATOR; |
| 60 |
static { |
56 |
static { |
| 61 |
String s = System.getProperty("line.separator"); //$NON-NLS-1$ |
57 |
String s = System.getProperty("line.separator"); //$NON-NLS-1$ |
| 62 |
LINE_SEPARATOR = s == null ? "\n" : s; //$NON-NLS-1$ |
58 |
LINE_SEPARATOR = s == null ? "\n" : s; //$NON-NLS-1$ |
| 63 |
} |
59 |
} |
| 64 |
/** The value written to the trace file if a null object is being traced */ |
60 |
/** The value written to the trace file if a null object is being traced */ |
| 65 |
public final static String NULL_VALUE = "<null>"; //$NON-NLS-1$ |
61 |
private final static String NULL_VALUE = "<null>"; //$NON-NLS-1$ |
| 66 |
/** */ |
62 |
/** */ |
| 67 |
private final static SecureAction secureAction = (SecureAction) AccessController.doPrivileged(SecureAction.createSecureAction()); |
63 |
private final static SecureAction secureAction = (SecureAction) AccessController.doPrivileged(SecureAction.createSecureAction()); |
| 68 |
/** A lock object used to synchronize access to the trace file */ |
64 |
/** A lock object used to synchronize access to the trace file */ |
| 69 |
protected final static Object writeLock = new Object(); |
65 |
private final static Object writeLock = new Object(); |
| 70 |
|
66 |
|
| 71 |
/******************* Tracing file attributes **************************/ |
67 |
/******************* Tracing file attributes **************************/ |
| 72 |
/** The default size a trace file can grow before it is rotated */ |
68 |
/** The default size a trace file can grow before it is rotated */ |
| 73 |
public static final int DEFAULT_TRACE_FILE_SIZE = 1000; // The value is in KB. |
69 |
private static final int DEFAULT_TRACE_FILE_SIZE = 1000; // The value is in KB. |
| 74 |
/** The default number of backup trace files */ |
70 |
/** The default number of backup trace files */ |
| 75 |
public static final int DEFAULT_TRACE_FILES = 10; |
71 |
private static final int DEFAULT_TRACE_FILES = 10; |
| 76 |
/** The minimum size limit for trace file rotation */ |
72 |
/** The minimum size limit for trace file rotation */ |
| 77 |
public static final int DEFAULT_TRACE_FILE_MIN_SIZE = 10; |
73 |
private static final int DEFAULT_TRACE_FILE_MIN_SIZE = 10; |
| 78 |
/** The extension used for log files */ |
74 |
/** The extension used for log files */ |
| 79 |
public static final String TRACE_FILE_EXTENSION = ".trace"; //$NON-NLS-1$ |
75 |
private static final String TRACE_FILE_EXTENSION = ".trace"; //$NON-NLS-1$ |
| 80 |
/** The extension markup to use for backup log files*/ |
76 |
/** The extension markup to use for backup log files*/ |
| 81 |
public static final String BACKUP_MARK = ".bak_"; //$NON-NLS-1$ |
77 |
private static final String BACKUP_MARK = ".bak_"; //$NON-NLS-1$ |
| 82 |
/** The maximum size that a trace file should grow (0 = unlimited) */ |
78 |
/** The maximum size that a trace file should grow (0 = unlimited) */ |
| 83 |
protected int maxTraceFileSize = DEFAULT_TRACE_FILE_SIZE; // The value is in KB. |
79 |
private int maxTraceFileSize = DEFAULT_TRACE_FILE_SIZE; // The value is in KB. |
| 84 |
/** The maximum number of trace files that should be saved */ |
80 |
/** The maximum number of trace files that should be saved */ |
| 85 |
protected int maxTraceFiles = DEFAULT_TRACE_FILES; |
81 |
private int maxTraceFiles = DEFAULT_TRACE_FILES; |
| 86 |
/** The index of the currently backed-up trace file */ |
82 |
/** The index of the currently backed-up trace file */ |
| 87 |
protected int backupTraceFileIndex = 0; |
83 |
private int backupTraceFileIndex = 0; |
| 88 |
|
84 |
|
| 89 |
/** An optional argument to specify the name of the class used by clients to trace messages. If no trace class is specified |
85 |
/** An optional argument to specify the name of the class used by clients to trace messages. If no trace class is specified |
| 90 |
* then the class calling this API is assumed to be the class being traced. |
86 |
* then the class calling this API is assumed to be the class being traced. |
| 91 |
*/ |
87 |
*/ |
| 92 |
protected Class traceClass = null; |
88 |
private String traceClass = null; |
| 93 |
/** The symbolic name of the bundle being traced */ |
89 |
/** The symbolic name of the bundle being traced */ |
| 94 |
protected String bundleSymbolicName = null; |
90 |
private String bundleSymbolicName = null; |
| 95 |
/** A flag to determine if the message being written is done to a new file (i.e. should the header information be written) */ |
91 |
/** A flag to determine if the message being written is done to a new file (i.e. should the header information be written) */ |
| 96 |
protected static boolean newSession = true; |
92 |
static boolean newSession = true; |
| 97 |
/** DebugOptions are used to determine if the specified bundle symbolic name + option-path has debugging enabled */ |
93 |
/** DebugOptions are used to determine if the specified bundle symbolic name + option-path has debugging enabled */ |
| 98 |
protected DebugOptions debugOptions = null; |
94 |
private DebugOptions debugOptions = null; |
| 99 |
|
95 |
|
| 100 |
/** |
96 |
/** |
| 101 |
* Construct a new EclipseDebugTrace for the specified bundle symbolic name and write messages to the specified |
97 |
* Construct a new EclipseDebugTrace for the specified bundle symbolic name and write messages to the specified |
|
Lines 119-125
Link Here
|
| 119 |
*/ |
115 |
*/ |
| 120 |
public EclipseDebugTrace(final String bundleSymbolicName, final DebugOptions debugOptions, final Class traceClass) { |
116 |
public EclipseDebugTrace(final String bundleSymbolicName, final DebugOptions debugOptions, final Class traceClass) { |
| 121 |
|
117 |
|
| 122 |
this.traceClass = traceClass; |
118 |
this.traceClass = traceClass != null ? traceClass.getName() : null; |
| 123 |
this.debugOptions = debugOptions; |
119 |
this.debugOptions = debugOptions; |
| 124 |
this.bundleSymbolicName = bundleSymbolicName; |
120 |
this.bundleSymbolicName = bundleSymbolicName; |
| 125 |
readLogProperties(); |
121 |
readLogProperties(); |
|
Lines 131-137
Link Here
|
| 131 |
* @param optionPath The <i>option-path</i> |
127 |
* @param optionPath The <i>option-path</i> |
| 132 |
* @return Returns true if debugging is enabled for the specified option-path on this bundle; Otherwise false. |
128 |
* @return Returns true if debugging is enabled for the specified option-path on this bundle; Otherwise false. |
| 133 |
*/ |
129 |
*/ |
| 134 |
protected final boolean isDebuggingEnabled(final String optionPath) { |
130 |
private final boolean isDebuggingEnabled(final String optionPath) { |
| 135 |
if (optionPath == null) |
131 |
if (optionPath == null) |
| 136 |
return true; |
132 |
return true; |
| 137 |
boolean debugEnabled = false; |
133 |
boolean debugEnabled = false; |
|
Lines 279-285
Link Here
|
| 279 |
* The array of StackTraceElement objects |
275 |
* The array of StackTraceElement objects |
| 280 |
* @return A String of the stack dump produced by the list of elements |
276 |
* @return A String of the stack dump produced by the list of elements |
| 281 |
*/ |
277 |
*/ |
| 282 |
protected final String convertStackTraceElementsToString(final StackTraceElement[] elements) { |
278 |
private final String convertStackTraceElementsToString(final StackTraceElement[] elements) { |
| 283 |
|
279 |
|
| 284 |
final StringBuffer buffer = new StringBuffer(); |
280 |
final StringBuffer buffer = new StringBuffer(); |
| 285 |
if (elements != null) { |
281 |
if (elements != null) { |
|
Lines 303-309
Link Here
|
| 303 |
* |
299 |
* |
| 304 |
* @param entry The FrameworkTraceEntry to write to the log file. |
300 |
* @param entry The FrameworkTraceEntry to write to the log file. |
| 305 |
*/ |
301 |
*/ |
| 306 |
protected void writeRecord(final FrameworkDebugTraceEntry entry) { |
302 |
private void writeRecord(final FrameworkDebugTraceEntry entry) { |
| 307 |
|
303 |
|
| 308 |
if (entry != null) { |
304 |
if (entry != null) { |
| 309 |
synchronized (EclipseDebugTrace.writeLock) { |
305 |
synchronized (EclipseDebugTrace.writeLock) { |
|
Lines 338-344
Link Here
|
| 338 |
/** |
334 |
/** |
| 339 |
* Reads the PROP_TRACE_SIZE_MAX and PROP_TRACE_FILE_MAX properties. |
335 |
* Reads the PROP_TRACE_SIZE_MAX and PROP_TRACE_FILE_MAX properties. |
| 340 |
*/ |
336 |
*/ |
| 341 |
protected void readLogProperties() { |
337 |
private void readLogProperties() { |
| 342 |
|
338 |
|
| 343 |
String newMaxTraceFileSize = secureAction.getProperty(PROP_TRACE_SIZE_MAX); |
339 |
String newMaxTraceFileSize = secureAction.getProperty(PROP_TRACE_SIZE_MAX); |
| 344 |
if (newMaxTraceFileSize != null) { |
340 |
if (newMaxTraceFileSize != null) { |
|
Lines 366-372
Link Here
|
| 366 |
* @param traceFile The tracing file |
362 |
* @param traceFile The tracing file |
| 367 |
* @return false if an error occurred trying to rotate the trace file |
363 |
* @return false if an error occurred trying to rotate the trace file |
| 368 |
*/ |
364 |
*/ |
| 369 |
protected boolean checkTraceFileSize(final File traceFile) { |
365 |
private boolean checkTraceFileSize(final File traceFile) { |
| 370 |
|
366 |
|
| 371 |
// 0 file size means there is no size limit |
367 |
// 0 file size means there is no size limit |
| 372 |
boolean isBackupOK = true; |
368 |
boolean isBackupOK = true; |
|
Lines 433-439
Link Here
|
| 433 |
* @param comment the comment to be written to the trace file |
429 |
* @param comment the comment to be written to the trace file |
| 434 |
* @throws IOException If an error occurs while writing the comment |
430 |
* @throws IOException If an error occurs while writing the comment |
| 435 |
*/ |
431 |
*/ |
| 436 |
protected void writeComment(final Writer traceWriter, final String comment) throws IOException { |
432 |
private void writeComment(final Writer traceWriter, final String comment) throws IOException { |
| 437 |
|
433 |
|
| 438 |
StringBuffer commentText = new StringBuffer(EclipseDebugTrace.TRACE_COMMENT); |
434 |
StringBuffer commentText = new StringBuffer(EclipseDebugTrace.TRACE_COMMENT); |
| 439 |
commentText.append(" "); //$NON-NLS-1$ |
435 |
commentText.append(" "); //$NON-NLS-1$ |
|
Lines 447-453
Link Here
|
| 447 |
* |
443 |
* |
| 448 |
* @return A formatted time stamp based on the {@link EclipseDebugTrace#TRACE_FILE_DATE_FORMATTER} formatter |
444 |
* @return A formatted time stamp based on the {@link EclipseDebugTrace#TRACE_FILE_DATE_FORMATTER} formatter |
| 449 |
*/ |
445 |
*/ |
| 450 |
protected final String getFormattedDate() { |
446 |
private final String getFormattedDate() { |
| 451 |
|
447 |
|
| 452 |
return this.getFormattedDate(System.currentTimeMillis()); |
448 |
return this.getFormattedDate(System.currentTimeMillis()); |
| 453 |
} |
449 |
} |
|
Lines 457-463
Link Here
|
| 457 |
* |
453 |
* |
| 458 |
* @return A formatted time stamp based on the {@link EclipseDebugTrace#TRACE_FILE_DATE_FORMATTER} formatter |
454 |
* @return A formatted time stamp based on the {@link EclipseDebugTrace#TRACE_FILE_DATE_FORMATTER} formatter |
| 459 |
*/ |
455 |
*/ |
| 460 |
protected final String getFormattedDate(long timestamp) { |
456 |
private final String getFormattedDate(long timestamp) { |
| 461 |
|
457 |
|
| 462 |
return EclipseDebugTrace.TRACE_FILE_DATE_FORMATTER.format(new Date(timestamp)); |
458 |
return EclipseDebugTrace.TRACE_FILE_DATE_FORMATTER.format(new Date(timestamp)); |
| 463 |
} |
459 |
} |
|
Lines 468-474
Link Here
|
| 468 |
* @param traceWriter the trace writer |
464 |
* @param traceWriter the trace writer |
| 469 |
* @throws IOException If an error occurs while writing this session information |
465 |
* @throws IOException If an error occurs while writing this session information |
| 470 |
*/ |
466 |
*/ |
| 471 |
protected void writeSession(final Writer traceWriter) throws IOException { |
467 |
private void writeSession(final Writer traceWriter) throws IOException { |
| 472 |
|
468 |
|
| 473 |
writeComment(traceWriter, EclipseDebugTrace.TRACE_NEW_SESSION + this.getFormattedDate()); |
469 |
writeComment(traceWriter, EclipseDebugTrace.TRACE_NEW_SESSION + this.getFormattedDate()); |
| 474 |
writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_VERSION_COMMENT + EclipseDebugTrace.TRACE_FILE_VERSION); |
470 |
writeComment(traceWriter, EclipseDebugTrace.TRACE_FILE_VERSION_COMMENT + EclipseDebugTrace.TRACE_FILE_VERSION); |
|
Lines 488-494
Link Here
|
| 488 |
* @param entry The trace entry object to write to the trace file |
484 |
* @param entry The trace entry object to write to the trace file |
| 489 |
* @throws IOException If an error occurs while writing this message |
485 |
* @throws IOException If an error occurs while writing this message |
| 490 |
*/ |
486 |
*/ |
| 491 |
protected void writeMessage(final Writer traceWriter, final FrameworkDebugTraceEntry entry) throws IOException { |
487 |
private void writeMessage(final Writer traceWriter, final FrameworkDebugTraceEntry entry) throws IOException { |
| 492 |
|
488 |
|
| 493 |
// format the trace entry |
489 |
// format the trace entry |
| 494 |
StringBuffer message = new StringBuffer(entry.getThreadName()); |
490 |
StringBuffer message = new StringBuffer(entry.getThreadName()); |
|
Lines 537-543
Link Here
|
| 537 |
* @param output an OutputStream to use for the Writer |
533 |
* @param output an OutputStream to use for the Writer |
| 538 |
* @return A Writer for the given OutputStream |
534 |
* @return A Writer for the given OutputStream |
| 539 |
*/ |
535 |
*/ |
| 540 |
protected Writer logForStream(OutputStream output) { |
536 |
private Writer logForStream(OutputStream output) { |
| 541 |
|
537 |
|
| 542 |
try { |
538 |
try { |
| 543 |
return new BufferedWriter(new OutputStreamWriter(output, "UTF-8")); //$NON-NLS-1$ |
539 |
return new BufferedWriter(new OutputStreamWriter(output, "UTF-8")); //$NON-NLS-1$ |
|
Lines 553-559
Link Here
|
| 553 |
* @param traceFile The tracing file |
549 |
* @param traceFile The tracing file |
| 554 |
* @return Returns a new Writer object |
550 |
* @return Returns a new Writer object |
| 555 |
*/ |
551 |
*/ |
| 556 |
protected Writer openWriter(final File traceFile) { |
552 |
private Writer openWriter(final File traceFile) { |
| 557 |
|
553 |
|
| 558 |
Writer traceWriter = null; |
554 |
Writer traceWriter = null; |
| 559 |
if (traceFile != null) { |
555 |
if (traceFile != null) { |
|
Lines 573-579
Link Here
|
| 573 |
* |
569 |
* |
| 574 |
* @param traceWriter The trace writer |
570 |
* @param traceWriter The trace writer |
| 575 |
*/ |
571 |
*/ |
| 576 |
protected void closeWriter(Writer traceWriter) { |
572 |
private void closeWriter(Writer traceWriter) { |
| 577 |
|
573 |
|
| 578 |
if (traceWriter != null) { |
574 |
if (traceWriter != null) { |
| 579 |
try { |
575 |
try { |