This is an automated email from the ASF dual-hosted git repository.

quantranhong1999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new 011735aab0 [ENHACEMENT] Log stacktraces in DEBUG mode for protocol 
level failures
011735aab0 is described below

commit 011735aab0ec8a7e863b6c3ea03f2819b12eada5
Author: Benoit TELLIER <[email protected]>
AuthorDate: Sat Jun 6 07:52:40 2026 +0200

    [ENHACEMENT] Log stacktraces in DEBUG mode for protocol level failures
---
 .../protocols/netty/BasicChannelInboundHandler.java      | 16 ++++++++++++----
 .../imapserver/netty/ImapChannelUpstreamHandler.java     | 14 +++++++++++---
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git 
a/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java
 
b/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java
index 12c8827238..014f67cf0e 100644
--- 
a/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java
+++ 
b/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java
@@ -282,13 +282,13 @@ public class BasicChannelInboundHandler extends 
ChannelInboundHandlerAdapter imp
                     transport.writeResponse(Response.DISCONNECT, session);
                 }
                 if (cause instanceof SocketException) {
-                    LOGGER.info("Socket exception encountered: {}", 
cause.getMessage());
+                    logExpectedException("Socket exception encountered", 
cause);
                 } else if (isSslHandshkeException(cause)) {
-                    LOGGER.info("SSH handshake rejected {}", 
cause.getMessage());
+                    logExpectedException("SSL handshake rejected", cause);
                 } else if (isNotSslRecordException(cause)) {
-                    LOGGER.info("Not an SSL record {}", cause.getMessage());
+                    logExpectedException("Not an SSL record", cause);
                 } else if (isSslException(cause)) {
-                    LOGGER.info("Encountered SSL exception: {}", 
cause.getMessage());
+                    logExpectedException("Encountered SSL exception", cause);
                 } else if (!(cause instanceof ClosedChannelException)) {
                     LOGGER.error("Unable to process request", cause);
                 }
@@ -297,6 +297,14 @@ public class BasicChannelInboundHandler extends 
ChannelInboundHandlerAdapter imp
         }
     }
 
+    private void logExpectedException(String message, Throwable cause) {
+        if (LOGGER.isDebugEnabled()) {
+            LOGGER.debug(message, cause);
+        } else {
+            LOGGER.info("{}: {}", message, cause.getMessage());
+        }
+    }
+
     private boolean isSslHandshkeException(Throwable cause) {
         return cause instanceof DecoderException &&
             cause.getCause() instanceof SSLHandshakeException;
diff --git 
a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapChannelUpstreamHandler.java
 
b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapChannelUpstreamHandler.java
index e4435a7786..0af14212a6 100644
--- 
a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapChannelUpstreamHandler.java
+++ 
b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapChannelUpstreamHandler.java
@@ -313,11 +313,11 @@ public class ImapChannelUpstreamHandler extends 
ChannelInboundHandlerAdapter imp
         String username = retrieveUsername(imapSession);
         try (Closeable closeable = mdc(imapSession).build()) {
             if (cause instanceof SocketException) {
-                LOGGER.info("Socket exception encountered for user {}: {}", 
username, cause.getMessage());
+                logExpectedException("Socket exception encountered for user " 
+ username, cause);
             } else if (isSslHandshkeException(cause)) {
-                LOGGER.info("SSH handshake rejected {}", cause.getMessage());
+                logExpectedException("SSL handshake rejected", cause);
             } else if (isNotSslRecordException(cause)) {
-                LOGGER.info("Not an SSL record {}", cause.getMessage());
+                logExpectedException("Not an SSL record", cause);
             } else if (!(cause instanceof ClosedChannelException)) {
                 LOGGER.error("Error while processing imap request", cause);
             }
@@ -351,6 +351,14 @@ public class ImapChannelUpstreamHandler extends 
ChannelInboundHandlerAdapter imp
         }
     }
 
+    private void logExpectedException(String message, Throwable cause) {
+        if (LOGGER.isDebugEnabled()) {
+            LOGGER.debug(message, cause);
+        } else {
+            LOGGER.info("{}: {}", message, cause.getMessage());
+        }
+    }
+
     private boolean isSslHandshkeException(Throwable cause) {
         return cause instanceof DecoderException
             && cause.getCause() instanceof SSLHandshakeException;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to