Log caught session exception cause if available
authorLyor Goldstein <lgoldstein@apache.org>
Tue, 12 Feb 2019 10:55:12 +0000 (12:55 +0200)
committerLyor Goldstein <lgoldstein@apache.org>
Wed, 13 Feb 2019 11:40:27 +0000 (13:40 +0200)
sshd-core/src/main/java/org/apache/sshd/common/session/helpers/SessionHelper.java

index a996d6d..41e85ac 100644 (file)
@@ -1022,9 +1022,22 @@ public abstract class SessionHelper extends AbstractKexFactoryManager implements
             return;
         }
 
-        log.warn("exceptionCaught({})[state={}] {}: {}", this, curState, t.getClass().getSimpleName(), t.getMessage());
+        log.warn("exceptionCaught({})[state={}] {}: {}",
+            this, curState, t.getClass().getSimpleName(), t.getMessage());
+        Throwable cause = t.getCause();
+        if ((cause != null) && GenericUtils.isSameReference(t, cause)) {
+            cause = null;
+        }
+        if (cause != null) {
+            log.warn("exceptionCaught({})[state={}] caused by {}: {}",
+                this, curState, cause.getClass().getSimpleName(), cause.getMessage());
+        }
+
         if (log.isDebugEnabled()) {
             log.debug("exceptionCaught(" + this + ")[state=" + curState + "] details", t);
+            if (cause != null) {
+                log.debug("exceptionCaught(" + this + ")[state=" + curState + "] cause", cause);
+            }
         }
 
         signalExceptionCaught(t);