From db2fbec5c4f02743e40de03b38a700f8343689df Mon Sep 17 00:00:00 2001 From: Henkes Date: Tue, 25 Aug 2015 12:50:18 -0500 Subject: [PATCH] Move exception logging to error filters --- .../java/com/netflix/zuul/filters/ZuulServletFilter.java | 5 ----- .../src/main/java/com/netflix/zuul/http/ZuulServlet.java | 8 ++------ .../src/main/groovy/filters/pre/ErrorResponse.groovy | 5 +++++ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/zuul-core/src/main/java/com/netflix/zuul/filters/ZuulServletFilter.java b/zuul-core/src/main/java/com/netflix/zuul/filters/ZuulServletFilter.java index 947e3aa51e..8e22648ffe 100644 --- a/zuul-core/src/main/java/com/netflix/zuul/filters/ZuulServletFilter.java +++ b/zuul-core/src/main/java/com/netflix/zuul/filters/ZuulServletFilter.java @@ -26,8 +26,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.runners.MockitoJUnitRunner; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; @@ -51,8 +49,6 @@ */ public class ZuulServletFilter implements Filter { - private static Logger LOG = LoggerFactory.getLogger(ZuulServletFilter.class); - private ZuulRunner zuulRunner; public void init(FilterConfig filterConfig) throws ServletException { @@ -113,7 +109,6 @@ void init(HttpServletRequest servletRequest, HttpServletResponse servletResponse void error(ZuulException e) { RequestContext.getCurrentContext().setThrowable(e); zuulRunner.error(); - LOG.error(e.getMessage(), e); } public void destroy() { diff --git a/zuul-core/src/main/java/com/netflix/zuul/http/ZuulServlet.java b/zuul-core/src/main/java/com/netflix/zuul/http/ZuulServlet.java index 5bd10b8260..0a97c6bd13 100644 --- a/zuul-core/src/main/java/com/netflix/zuul/http/ZuulServlet.java +++ b/zuul-core/src/main/java/com/netflix/zuul/http/ZuulServlet.java @@ -25,8 +25,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.runners.MockitoJUnitRunner; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.servlet.ServletConfig; import javax.servlet.ServletException; @@ -47,10 +45,9 @@ * Time: 10:44 AM */ public class ZuulServlet extends HttpServlet { - + private static final long serialVersionUID = -3374242278843351500L; private ZuulRunner zuulRunner; - private static Logger LOG = LoggerFactory.getLogger(ZuulServlet.class); @Override @@ -146,7 +143,6 @@ void init(HttpServletRequest servletRequest, HttpServletResponse servletResponse void error(ZuulException e) { RequestContext.getCurrentContext().setThrowable(e); zuulRunner.error(); - LOG.error(e.getMessage(), e); } @RunWith(MockitoJUnitRunner.class) @@ -196,7 +192,7 @@ public void testProcessZuulFilter() { RequestContext.testSetCurrentContext(null); } catch (Exception e) { - LOG.error(e.getMessage(), e); + e.printStackTrace(); } diff --git a/zuul-netflix-webapp/src/main/groovy/filters/pre/ErrorResponse.groovy b/zuul-netflix-webapp/src/main/groovy/filters/pre/ErrorResponse.groovy index 6bdba2fbfa..58beed032a 100644 --- a/zuul-netflix-webapp/src/main/groovy/filters/pre/ErrorResponse.groovy +++ b/zuul-netflix-webapp/src/main/groovy/filters/pre/ErrorResponse.groovy @@ -26,12 +26,16 @@ import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito import org.mockito.runners.MockitoJUnitRunner +import org.slf4j.Logger +import org.slf4j.LoggerFactory import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletResponse class ErrorResponse extends ZuulFilter { + private static final Logger LOG = LoggerFactory.getLogger(ErrorResponse.class); + @Override String filterType() { return 'error' @@ -53,6 +57,7 @@ class ErrorResponse extends ZuulFilter { RequestContext context = RequestContext.currentContext Throwable ex = context.getThrowable() try { + LOG.error(ex.getMessage(), ex); throw ex } catch (ZuulException e) { String cause = e.errorCause