org.mentalog.LogException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of menta-log Show documentation
Show all versions of menta-log Show documentation
A log library that embraces the kiss principle.
package org.mentalog;
public class LogException extends RuntimeException {
protected final Throwable rootCause;
public LogException() {
super();
this.rootCause = null;
}
public LogException(Throwable e) {
super(getMsg(e), e);
Throwable root = getRootCause(e);
this.setStackTrace(root.getStackTrace());
this.rootCause = root == this ? null : root;
}
public LogException(String msg) {
super(msg);
this.rootCause = null;
}
public LogException(String msg, Throwable e) {
super(msg, e);
Throwable root = getRootCause(e);
this.setStackTrace(root.getStackTrace());
this.rootCause = root == this ? null : root;
}
private static String getMsg(Throwable t) {
Throwable root = getRootCause(t);
String msg = root.getMessage();
if (msg == null || msg.length() == 0) {
msg = t.getMessage();
if (msg == null || msg.length() == 0) {
return root.getClass().getName();
}
}
return msg;
}
private static Throwable getRootCause(Throwable t) {
Throwable root = t.getCause();
if (root == null) {
return t;
}
while (root.getCause() != null) {
root = root.getCause();
}
return root;
}
@Override
public Throwable getCause() {
return rootCause;
}
}