Skip to content

Commit

Permalink
Merge branch 'dev-3.0.8' into dev-3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Zhou committed Jun 21, 2012
2 parents a31d583 + a6c6aed commit c63ed9c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,12 @@ public void logError(Logger log, LoggingDetail detail) {
switch (detail) {
case detailed:
// 打印详细异常信息
log.error("Error occurred while process request " + getRequestURI(), getException());
log.error("Failed to process request " + getRequestURI() + ", the root cause was " + getRootCauseMessage(), getException());
break;

case brief:
// 打印root cause的message
Throwable rootCause = getRootCause(getException());
String message = rootCause.getClass().getSimpleName();

if (!isBlank(rootCause.getMessage())) {
message += ": " + rootCause.getMessage();
}

log.error(message);
log.error(getRootCauseMessage());

break;

Expand All @@ -256,6 +249,17 @@ public void logError(Logger log, LoggingDetail detail) {
}
}

private String getRootCauseMessage() {
Throwable rootCause = getRootCause(getException());
String message = rootCause.getClass().getSimpleName();

if (!isBlank(rootCause.getMessage())) {
message += ": " + rootCause.getMessage();
}

return message;
}

@Override
public String toString() {
return getStatusCode() + " " + getMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void logError() {
helper.init("myServlet", e, null);

reset(log);
log.error("Error occurred while process request /app1", e);
log.error("Failed to process request /app1, the root cause was IOException: ioe", e);
replay(log);
helper.logError(log);
verify(log);
Expand All @@ -215,14 +215,14 @@ public void logError2() {
helper.init("myServlet", e, null);

reset(log);
log.error("Error occurred while process request /app1", e);
log.error("Failed to process request /app1, the root cause was IllegalArgumentException: iae", e);
replay(log);
helper.logError(log, null);
verify(log);

// detailed
reset(log);
log.error("Error occurred while process request /app1", e);
log.error("Failed to process request /app1, the root cause was IllegalArgumentException: iae", e);
replay(log);
helper.logError(log, detailed);
verify(log);
Expand Down

0 comments on commit c63ed9c

Please sign in to comment.