Skip to content

Commit 035c419

Browse files
committed
Bug 573109: Add new logging options for terminal
Change-Id: I0c35b7ce0c4350081eac6ace974dbcee3e0f103d
1 parent 01a17e2 commit 035c419

File tree

1 file changed

+28
-12
lines changed
  • terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api

1 file changed

+28
-12
lines changed

terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/Logger.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ public static final boolean isLogEnabled() {
164164
* Logs the specified message. Do not append a newline to parameter
165165
* <i>message</i>. This method does that for you.
166166
*
167+
* Does not write to the message to the Eclipse log
168+
*
167169
* @param message A String containing the message to log.
168170
*/
169171
public static final void log(String message) {
@@ -174,29 +176,43 @@ public static final void log(String message) {
174176
}
175177

176178
/**
177-
* Writes a stack trace for an exception to both Standard Error and to the
178-
* log file.
179+
* Writes an error message to the Terminal log and the Eclipse log
180+
* @since 5.2
181+
*/
182+
public static final void logError(String message) {
183+
logStatus(new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, IStatus.OK, message, null));
184+
}
185+
186+
/**
187+
* Writes an exception to the Terminal log and the Eclipse log
179188
*/
180189
public static final void logException(Exception ex) {
190+
logStatus(new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, IStatus.OK, ex.getMessage(), ex));
191+
}
192+
193+
/**
194+
* Writes a Status to the Terminal log and the Eclipse log
195+
* @since 5.2
196+
*/
197+
public static final void logStatus(IStatus status) {
181198
// log in eclipse error log
182199
if (TerminalPlugin.getDefault() != null) {
183-
TerminalPlugin.getDefault().getLog()
184-
.log(new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, IStatus.OK, ex.getMessage(), ex));
200+
TerminalPlugin.getDefault().getLog().log(status);
185201
} else {
186-
ex.printStackTrace();
202+
System.err.println(status);
203+
if (status.getException() != null) {
204+
status.getException().printStackTrace();
205+
}
187206
}
188207
// Additional Tracing for debug purposes:
189208
// Read my own stack to get the class name, method name, and line number
190209
// of where this method was called
191210
if (logStream != null) {
192-
PrintStream tmpStream = System.err;
193-
if (logStream != null) {
194-
tmpStream = logStream;
211+
logStream.println(getCallSiteDescription() + ": " + //$NON-NLS-1$
212+
status);
213+
if (status.getException() != null) {
214+
status.getException().printStackTrace(logStream);
195215
}
196-
197-
tmpStream.println(getCallSiteDescription() + ": " + //$NON-NLS-1$
198-
"Caught exception: " + ex); //$NON-NLS-1$
199-
ex.printStackTrace(tmpStream);
200216
}
201217
}
202218

0 commit comments

Comments
 (0)