james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [01/34] james-project git commit: JAMES-2085 Systematically log uncatched errors with WARN/ERROR level with stacktraces
Date Wed, 05 Jul 2017 13:59:08 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 9d8d71cd0 -> 1128983f4


JAMES-2085 Systematically log uncatched errors with WARN/ERROR level with stacktraces


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/bae03df6
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/bae03df6
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/bae03df6

Branch: refs/heads/master
Commit: bae03df63c56dbe55ae569e16a168090fb8db150
Parents: 02d86a4
Author: benwa <btellier@linagora.com>
Authored: Mon Jul 3 10:04:59 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Jul 5 17:11:10 2017 +0700

----------------------------------------------------------------------
 .../org/apache/james/protocols/api/Protocol.java    |  6 ++++++
 .../apache/james/protocols/api/ProtocolImpl.java    |  3 +++
 .../netty/BasicChannelUpstreamHandler.java          | 16 ++++++++++------
 .../java/org/apache/james/jmap/JMAPServlet.java     |  7 +++++--
 .../netty/ImapChannelUpstreamHandler.java           |  3 +--
 .../netty/ManageSieveChannelUpstreamHandler.java    |  3 +--
 6 files changed, 26 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/bae03df6/protocols/api/src/main/java/org/apache/james/protocols/api/Protocol.java
----------------------------------------------------------------------
diff --git a/protocols/api/src/main/java/org/apache/james/protocols/api/Protocol.java b/protocols/api/src/main/java/org/apache/james/protocols/api/Protocol.java
index 5ba5bc3..00c47b3 100644
--- a/protocols/api/src/main/java/org/apache/james/protocols/api/Protocol.java
+++ b/protocols/api/src/main/java/org/apache/james/protocols/api/Protocol.java
@@ -20,6 +20,7 @@
 package org.apache.james.protocols.api;
 
 import org.apache.james.protocols.api.handler.ProtocolHandlerChain;
+import org.apache.james.protocols.api.logger.Logger;
 
 /**
  * Define a protocol
@@ -48,4 +49,9 @@ public interface Protocol {
      */
     ProtocolSession newSession(ProtocolTransport transport);
 
+    /**
+     * @return The logger associated with the protocol
+     */
+    Logger getProtocolLogger();
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bae03df6/protocols/api/src/main/java/org/apache/james/protocols/api/ProtocolImpl.java
----------------------------------------------------------------------
diff --git a/protocols/api/src/main/java/org/apache/james/protocols/api/ProtocolImpl.java
b/protocols/api/src/main/java/org/apache/james/protocols/api/ProtocolImpl.java
index 53d4827..d82cb9f 100644
--- a/protocols/api/src/main/java/org/apache/james/protocols/api/ProtocolImpl.java
+++ b/protocols/api/src/main/java/org/apache/james/protocols/api/ProtocolImpl.java
@@ -61,4 +61,7 @@ public class ProtocolImpl implements Protocol{
         return config;
     }
 
+    public Logger getProtocolLogger() {
+        return logger;
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bae03df6/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelUpstreamHandler.java
----------------------------------------------------------------------
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelUpstreamHandler.java
b/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelUpstreamHandler.java
index 1464b2b..26e6ee8 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelUpstreamHandler.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelUpstreamHandler.java
@@ -35,6 +35,7 @@ import org.apache.james.protocols.api.handler.DisconnectHandler;
 import org.apache.james.protocols.api.handler.LineHandler;
 import org.apache.james.protocols.api.handler.ProtocolHandlerChain;
 import org.apache.james.protocols.api.handler.ProtocolHandlerResultHandler;
+import org.apache.james.protocols.api.logger.Logger;
 import org.jboss.netty.buffer.ChannelBuffer;
 import org.jboss.netty.channel.Channel;
 import org.jboss.netty.channel.ChannelHandler.Sharable;
@@ -165,9 +166,7 @@ public class BasicChannelUpstreamHandler extends SimpleChannelUpstreamHandler
{
     @Override
     public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
{
         ProtocolSession session = (ProtocolSession) ctx.getAttachment();
-        if (session != null) {
-            session.getLogger().info("Connection closed for " + session.getRemoteAddress().getAddress().getHostAddress());
-        }
+        getLogger(session).info("Connection closed for " + session.getRemoteAddress().getAddress().getHostAddress());
         cleanup(ctx);
 
         super.channelClosed(ctx, e);
@@ -221,11 +220,16 @@ public class BasicChannelUpstreamHandler extends SimpleChannelUpstreamHandler
{
                 } 
                 transport.writeResponse(Response.DISCONNECT, session);
             }
-            if (session != null) {
-                session.getLogger().debug("Unable to process request", e.getCause());
-            }
+            getLogger(session).error("Unable to process request", e.getCause());
             cleanup(ctx);            
         }
     }
 
+    private Logger getLogger(ProtocolSession session) {
+        if (session != null) {
+            return session.getLogger();
+        }
+        return protocol.getProtocolLogger();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bae03df6/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServlet.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServlet.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServlet.java
index d07a89b..2b17bd8 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServlet.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServlet.java
@@ -48,7 +48,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 
 public class JMAPServlet extends HttpServlet {
 
-    public static final Logger LOG = LoggerFactory.getLogger(JMAPServlet.class);
+    public static final Logger LOGGER = LoggerFactory.getLogger(JMAPServlet.class);
     public static final String JSON_CONTENT_TYPE = "application/json";
     public static final String JSON_CONTENT_TYPE_UTF8 = "application/json; charset=UTF-8";
 
@@ -78,8 +78,11 @@ public class JMAPServlet extends HttpServlet {
             resp.setContentType(JSON_CONTENT_TYPE);
             objectMapper.writeValue(resp.getOutputStream(), responses);
         } catch (IOException e) {
-            LOG.error("error handling request", e);
+            LOGGER.warn("error handling request", e);
             resp.setStatus(SC_BAD_REQUEST);
+        } catch (Exception e) {
+            LOGGER.error("Error handling request", e);
+            throw new ServletException(e);
         } finally {
             timeMetric.stopAndPublish();
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bae03df6/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapChannelUpstreamHandler.java
----------------------------------------------------------------------
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 50114ec..40916fd 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
@@ -141,8 +141,7 @@ public class ImapChannelUpstreamHandler extends SimpleChannelUpstreamHandler
imp
     @Override
     public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception
{
         
-        getLogger(ctx.getChannel()).warn("Error while processing imap request: " + e.getCause().getClass().getName()
+ " - " + e.getCause().getMessage());
-        getLogger(ctx.getChannel()).debug("Error while processing imap request", e.getCause());
+        getLogger(ctx.getChannel()).warn("Error while processing imap request", e.getCause());
 
         if (e.getCause() instanceof TooLongFrameException) {
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/bae03df6/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java
b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java
index 636017b..a603161 100644
--- a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java
+++ b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java
@@ -79,8 +79,7 @@ public class ManageSieveChannelUpstreamHandler extends SimpleChannelUpstreamHand
 
     @Override
     public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception
{
-        getLogger(ctx.getChannel()).warn("Error while processing ManageSieve request: " +
e.getCause().getClass().getName() + " - " + e.getCause().getMessage());
-        getLogger(ctx.getChannel()).debug("Error while processing ManageSieve request", e.getCause());
+        getLogger(ctx.getChannel()).warn("Error while processing ManageSieve request", e.getCause());
 
         if (e.getCause() instanceof TooLongFrameException) {
             // Max line length exceeded


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message