cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1190497 - in /cxf/trunk/rt/core/src: main/java/org/apache/cxf/interceptor/ test/java/org/apache/cxf/interceptor/
Date Fri, 28 Oct 2011 18:48:45 GMT
Author: cschneider
Date: Fri Oct 28 18:48:44 2011
New Revision: 1190497

URL: http://svn.apache.org/viewvc?rev=1190497&view=rev
Log:
CXF-3888 Different log categories for each service 

Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
    cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java?rev=1190497&r1=1190496&r2=1190497&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java
Fri Oct 28 18:48:44 2011
@@ -23,6 +23,8 @@ import java.io.FileWriter;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -31,11 +33,14 @@ import javax.xml.transform.Transformer;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.XMLUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.InterfaceInfo;
 
 /**
  * A simple logging handler which outputs the bytes of the message to the
@@ -47,6 +52,8 @@ public abstract class AbstractLoggingInt
     protected PrintWriter writer;
     protected boolean prettyLogging;
     
+    private Map<String, Logger> messageLoggers = new HashMap<String, Logger>();
+    
     public AbstractLoggingInterceptor(String phase) {
         super(phase);
     }
@@ -55,6 +62,23 @@ public abstract class AbstractLoggingInt
     }
     
     protected abstract Logger getLogger();
+    
+    Logger getMessageLogger(Message message) {
+        EndpointInfo endpoint = message.getExchange().getEndpoint().getEndpointInfo();
+        String serviceName = endpoint.getService().getName().getLocalPart();
+        InterfaceInfo iface = endpoint.getService().getInterface();
+        String portName = endpoint.getName().getLocalPart();
+        String portTypeName = iface.getName().getLocalPart();
+        String logName = "org.apache.cxf.services." + serviceName + "." 
+            + portName + "." + portTypeName;
+        Logger logger = endpoint.getProperty("MessageLogger", Logger.class);
+        if (logger == null) {
+            logger = LogUtils.getL7dLogger(this.getClass(), null, logName);
+            endpoint.setProperty("MessageLogger", logger);
+            messageLoggers.put(logName, logger);
+        }
+        return logger;
+    }
 
     public void setOutputLocation(String s) {
         if (s == null || "<logger>".equals(s)) {
@@ -141,14 +165,14 @@ public abstract class AbstractLoggingInt
         return originalLogString;
     } 
 
-    protected void log(String message) {
+    protected void log(Logger logger, String message) {
         message = transform(message);
         if (writer != null) {
             writer.println(message);
             // Flushing the writer to make sure the message is written
             writer.flush();
-        } else if (getLogger().isLoggable(Level.INFO)) {
-            getLogger().info(message);
+        } else if (logger.isLoggable(Level.INFO)) {
+            logger.info(message);
         }
     }
     

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java?rev=1190497&r1=1190496&r2=1190497&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java Fri
Oct 28 18:48:44 2011
@@ -69,12 +69,13 @@ public class LoggingInInterceptor extend
     }
     
     public void handleMessage(Message message) throws Fault {
-        if (writer != null || getLogger().isLoggable(Level.INFO)) {
-            logging(message);
+        Logger logger = getMessageLogger(message);
+        if (writer != null || logger.isLoggable(Level.INFO)) {
+            logging(logger, message);
         }
     }
 
-    protected void logging(Message message) throws Fault {
+    protected void logging(Logger logger, Message message) throws Fault {
         if (message.containsKey(LoggingMessage.ID_KEY)) {
             return;
         }
@@ -144,7 +145,7 @@ public class LoggingInInterceptor extend
                 throw new Fault(e);
             }
         }
-        log(buffer.toString());
+        log(logger, buffer.toString());
     }
 
     @Override

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java?rev=1190497&r1=1190496&r2=1190497&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
Fri Oct 28 18:48:44 2011
@@ -63,14 +63,15 @@ public class LoggingOutInterceptor exten
         if (os == null) {
             return;
         }
-        if (getLogger().isLoggable(Level.INFO) || writer != null) {
+        Logger logger = getMessageLogger(message);
+        if (logger.isLoggable(Level.INFO) || writer != null) {
             // Write the output while caching it for the log message
             boolean hasLogged = message.containsKey(LOG_SETUP);
             if (!hasLogged) {
                 message.put(LOG_SETUP, Boolean.TRUE);
                 final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(os);
                 message.setContent(OutputStream.class, newOut);
-                newOut.registerCallback(new LoggingCallback(message, os));
+                newOut.registerCallback(new LoggingCallback(logger, message, os));
             }
         }
     }
@@ -79,8 +80,11 @@ public class LoggingOutInterceptor exten
         
         private final Message message;
         private final OutputStream origStream;
+        @SuppressWarnings("PMD")
+        private final Logger logger;
         
-        public LoggingCallback(final Message msg, final OutputStream os) {
+        public LoggingCallback(final Logger logger, final Message msg, final OutputStream
os) {
+            this.logger = logger;
             this.message = msg;
             this.origStream = os;
         }
@@ -144,7 +148,7 @@ public class LoggingOutInterceptor exten
                 //ignore
             }
 
-            log(buffer.toString());
+            log(logger, buffer.toString());
             try {
                 //empty out the cache
                 cos.lockOutputStream();

Modified: cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java?rev=1190497&r1=1190496&r2=1190497&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
(original)
+++ cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
Fri Oct 28 18:48:44 2011
@@ -21,7 +21,9 @@ package org.apache.cxf.interceptor;
 
 import java.io.ByteArrayOutputStream;
 import java.io.PrintWriter;
+import java.util.logging.Logger;
 
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
@@ -46,7 +48,8 @@ public class LoggingOutInterceptorTest e
         Message message = new MessageImpl();
         message.setExchange(new ExchangeImpl());
         message.put(Message.CONTENT_TYPE, "application/xml");
-        LoggingOutInterceptor.LoggingCallback l = p.new LoggingCallback(message, cos);
+        Logger logger = LogUtils.getL7dLogger(this.getClass());
+        LoggingOutInterceptor.LoggingCallback l = p.new LoggingCallback(logger, message,
cos);
         l.onClose(cos);
         String str = baos.toString();
         //format has changed



Mime
View raw message