mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
Bug 573109: Add new logging options for terminal
Change-Id: I0c35b7ce0c4350081eac6ace974dbcee3e0f103d
This commit is contained in:
parent
b7d017572d
commit
4ef3cb7f30
1 changed files with 28 additions and 12 deletions
|
@ -164,6 +164,8 @@ public final class Logger {
|
||||||
* Logs the specified message. Do not append a newline to parameter
|
* Logs the specified message. Do not append a newline to parameter
|
||||||
* <i>message</i>. This method does that for you.
|
* <i>message</i>. This method does that for you.
|
||||||
*
|
*
|
||||||
|
* Does not write to the message to the Eclipse log
|
||||||
|
*
|
||||||
* @param message A String containing the message to log.
|
* @param message A String containing the message to log.
|
||||||
*/
|
*/
|
||||||
public static final void log(String message) {
|
public static final void log(String message) {
|
||||||
|
@ -174,29 +176,43 @@ public final class Logger {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a stack trace for an exception to both Standard Error and to the
|
* Writes an error message to the Terminal log and the Eclipse log
|
||||||
* log file.
|
* @since 5.2
|
||||||
|
*/
|
||||||
|
public static final void logError(String message) {
|
||||||
|
logStatus(new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, IStatus.OK, message, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes an exception to the Terminal log and the Eclipse log
|
||||||
*/
|
*/
|
||||||
public static final void logException(Exception ex) {
|
public static final void logException(Exception ex) {
|
||||||
|
logStatus(new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, IStatus.OK, ex.getMessage(), ex));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a Status to the Terminal log and the Eclipse log
|
||||||
|
* @since 5.2
|
||||||
|
*/
|
||||||
|
public static final void logStatus(IStatus status) {
|
||||||
// log in eclipse error log
|
// log in eclipse error log
|
||||||
if (TerminalPlugin.getDefault() != null) {
|
if (TerminalPlugin.getDefault() != null) {
|
||||||
TerminalPlugin.getDefault().getLog()
|
TerminalPlugin.getDefault().getLog().log(status);
|
||||||
.log(new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, IStatus.OK, ex.getMessage(), ex));
|
|
||||||
} else {
|
} else {
|
||||||
ex.printStackTrace();
|
System.err.println(status);
|
||||||
|
if (status.getException() != null) {
|
||||||
|
status.getException().printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Additional Tracing for debug purposes:
|
// Additional Tracing for debug purposes:
|
||||||
// Read my own stack to get the class name, method name, and line number
|
// Read my own stack to get the class name, method name, and line number
|
||||||
// of where this method was called
|
// of where this method was called
|
||||||
if (logStream != null) {
|
if (logStream != null) {
|
||||||
PrintStream tmpStream = System.err;
|
logStream.println(getCallSiteDescription() + ": " + //$NON-NLS-1$
|
||||||
if (logStream != null) {
|
status);
|
||||||
tmpStream = logStream;
|
if (status.getException() != null) {
|
||||||
|
status.getException().printStackTrace(logStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpStream.println(getCallSiteDescription() + ": " + //$NON-NLS-1$
|
|
||||||
"Caught exception: " + ex); //$NON-NLS-1$
|
|
||||||
ex.printStackTrace(tmpStream);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue