1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 18:56:02 +02:00

Logger logs errors to eclipse error log

This commit is contained in:
Michael Scharf 2007-05-26 02:06:42 +00:00
parent 966d8da9e6
commit deea717d27

View file

@ -17,6 +17,10 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.tm.internal.terminal.control.impl.TerminalPlugin;
/**
* A simple logger class. Every method in this class is static, so they can be
* called from both class and instance methods. To use this class, write code
@ -163,25 +167,28 @@ public final class Logger {
* log file.
*/
public static final void logException(Exception ex) {
// log in eclipse error log
TerminalPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TerminalPlugin.PLUGIN_ID, IStatus.OK, ex.getMessage(), ex));
// Read my own stack to get the class name, method name, and line number
// of
// where this method was called.
if(logStream!=null) {
StackTraceElement caller = new Throwable().getStackTrace()[1];
int lineNumber = caller.getLineNumber();
String className = caller.getClassName();
String methodName = caller.getMethodName();
className = className.substring(className.lastIndexOf('.') + 1);
StackTraceElement caller = new Throwable().getStackTrace()[1];
int lineNumber = caller.getLineNumber();
String className = caller.getClassName();
String methodName = caller.getMethodName();
className = className.substring(className.lastIndexOf('.') + 1);
PrintStream tmpStream = System.err;
PrintStream tmpStream = System.err;
if (logStream != null) {
tmpStream = logStream;
}
if (logStream != null) {
tmpStream = logStream;
tmpStream.println(className
+ "." + methodName + ":" + lineNumber + ": " + //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
"Caught exception: " + ex); //$NON-NLS-1$
ex.printStackTrace(tmpStream);
}
tmpStream.println(className
+ "." + methodName + ":" + lineNumber + ": " + //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
"Caught exception: " + ex); //$NON-NLS-1$
ex.printStackTrace(tmpStream);
}
}