mirror of https://github.com/apache/cloudstack.git
bug 10375: Added logging for exception causes
This commit is contained in:
parent
1d4bee51e7
commit
38ebac207b
|
|
@ -21,7 +21,7 @@
|
|||
<classpathentry exported="true" kind="lib" path="cloud-jsch-0.1.42.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="cloud-jstl-1.2.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="cloud-libvirt-0.4.5.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="cloud-log4j.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="cloud-log4j.jar" sourcepath="/home/dev/thirdparty/apache-log4j-1.2.16/src/main/java"/>
|
||||
<classpathentry exported="true" kind="lib" path="cloud-mysql-connector-java-5.1.7-bin.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="cloud-servlet-api.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="cloud-trilead-ssh2-build213.jar"/>
|
||||
|
|
|
|||
|
|
@ -67,22 +67,35 @@ public class CglibThrowableRenderer implements ThrowableRenderer {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String[] doRender(final Throwable throwable) {
|
||||
public String[] doRender(final Throwable th) {
|
||||
try {
|
||||
Object[] noArgs = null;
|
||||
Object[] elements = (Object[])getStackTraceMethod.invoke(throwable, noArgs);
|
||||
ArrayList<String> lines = new ArrayList<String>(elements.length + 1);
|
||||
ArrayList<String> lines = new ArrayList<String>();
|
||||
Throwable throwable = th;
|
||||
lines.add(throwable.toString());
|
||||
Map classMap = new HashMap();
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
if (!(elements[i] instanceof StackTraceElement) || !((StackTraceElement)elements[i]).getFileName().equals("<generated>")) {
|
||||
int start = 0;
|
||||
do {
|
||||
Object[] elements = (Object[])getStackTraceMethod.invoke(throwable, noArgs);
|
||||
for (int i = 0; i < elements.length - start; i++) {
|
||||
if (elements[i] instanceof StackTraceElement) {
|
||||
StackTraceElement stack = (StackTraceElement)elements[i];
|
||||
if (stack.getFileName().equals("<generated>") || stack.getFileName().equals("MethodProxy.java")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
lines.add(formatElement(elements[i], classMap));
|
||||
}
|
||||
}
|
||||
if (start != 0) {
|
||||
lines.add("\t... " + start + " more");
|
||||
}
|
||||
throwable = throwable.getCause();
|
||||
if (throwable != null) {
|
||||
lines.add("Caused by: " + throwable.toString());
|
||||
start = elements.length - 1;
|
||||
}
|
||||
} while (throwable != null);
|
||||
return lines.toArray(new String[lines.size()]);
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -12,9 +12,24 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
|||
public class CglibThrowableRendererTest extends TestCase {
|
||||
private final static Logger s_logger = Logger.getLogger(CglibThrowableRendererTest.class);
|
||||
public static class Test {
|
||||
public void exception1() {
|
||||
throw new IllegalArgumentException("What a bad exception");
|
||||
}
|
||||
|
||||
public void exception2() {
|
||||
try {
|
||||
exception1();
|
||||
} catch (Exception e) {
|
||||
throw new CloudRuntimeException("exception2", e);
|
||||
}
|
||||
}
|
||||
@DB
|
||||
public void exception() {
|
||||
throw new CloudRuntimeException("exception");
|
||||
try {
|
||||
exception2();
|
||||
} catch (Exception e) {
|
||||
throw new CloudRuntimeException("exception", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -26,5 +41,4 @@ public class CglibThrowableRendererTest extends TestCase {
|
|||
s_logger.warn("exception caught", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue