You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2017/11/08 16:32:48 UTC

[cxf] branch master updated: [CXF-7389] Logging 404 as FINE in other places

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

sergeyb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 68ed35f  [CXF-7389] Logging 404 as FINE in other places
68ed35f is described below

commit 68ed35f4f1b3f550c547ab9ce6bd3a492228b332
Author: Sergey Beryozkin <sb...@gmail.com>
AuthorDate: Wed Nov 8 16:32:34 2017 +0000

    [CXF-7389] Logging 404 as FINE in other places
---
 .../apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java  | 11 ++++++++++-
 .../org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java  |  4 +++-
 .../src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java  |  2 +-
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
index 77938a1..b1c8379 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
@@ -22,6 +22,7 @@ package org.apache.cxf.jaxrs.impl;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.ws.rs.NotFoundException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
@@ -68,7 +69,7 @@ public class WebApplicationExceptionMapper
             ? buildErrorMessage(r, ex) : null;
         if (flogger == null
             || !flogger.faultOccurred(ex, errorMessage, msg)) {
-            Level level = printStackTrace ? Level.WARNING : Level.FINE;
+            Level level = printStackTrace ? getStackTraceLogLevel(msg, r) : Level.FINE;
             LOG.log(level, ExceptionUtils.getStackTrace(ex));
         }
 
@@ -79,6 +80,14 @@ public class WebApplicationExceptionMapper
         return r;
     }
 
+    protected Level getStackTraceLogLevel(Message msg, Response r) {
+        if (r.getStatus() == 404) {
+            Level logLevel = JAXRSUtils.getExceptionLogLevel(msg, NotFoundException.class);
+            return logLevel == null ? Level.FINE : logLevel;
+        }
+        return Level.WARNING;
+    }
+
     protected String buildErrorMessage(Response r, WebApplicationException ex) {
         StringBuilder sb = new StringBuilder();
         sb.append(ERROR_MESSAGE_START).append(r.getStatus());
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
index d7be9b3..c07aaf1 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
@@ -27,6 +27,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.ws.rs.HttpMethod;
+import javax.ws.rs.NotFoundException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -163,7 +164,8 @@ public class JAXRSInInterceptor extends AbstractPhaseInterceptor<Message> {
                                                    BUNDLE,
                                                    message.get(Message.REQUEST_URI),
                                                    rawPath);
-            LOG.warning(errorMsg.toString());
+            Level logLevel = JAXRSUtils.getExceptionLogLevel(message, NotFoundException.class);
+            LOG.log(logLevel == null ? Level.FINE : logLevel, errorMsg.toString());
             Response resp = JAXRSUtils.createResponse(resources, message, errorMsg.toString(),
                     Response.Status.NOT_FOUND.getStatusCode(), false);
             throw ExceptionUtils.toNotFoundException(null, resp);
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
index 23cfd58..1c9400b 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
@@ -539,7 +539,7 @@ public final class JAXRSUtils {
 
     
     
-    private static Level getExceptionLogLevel(Message message, Class<? extends WebApplicationException> exClass) {
+    public static Level getExceptionLogLevel(Message message, Class<? extends WebApplicationException> exClass) {
         Level logLevel = null;
         Object logLevelProp = message.get(exClass.getName() + ".log.level");
         if (logLevelProp != null) {

-- 
To stop receiving notification emails like this one, please contact
['"commits@cxf.apache.org" <co...@cxf.apache.org>'].