cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7254] Adding SlF4jNoMdcEventSender and using it by default, optimizing the property reporting (no portname.etc for JAXRS)
Date Fri, 24 Feb 2017 12:38:24 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 91ef0687e -> 5022be0c1


[CXF-7254] Adding SlF4jNoMdcEventSender and using it by default, optimizing the property reporting
(no portname.etc for JAXRS)


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/5022be0c
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/5022be0c
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/5022be0c

Branch: refs/heads/master
Commit: 5022be0c15d90800ee983fe94b07a10a54814991
Parents: 91ef068
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Feb 24 12:38:10 2017 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Feb 24 12:38:10 2017 +0000

----------------------------------------------------------------------
 .../cxf/ext/logging/LoggingInInterceptor.java   |  4 +-
 .../cxf/ext/logging/LoggingOutInterceptor.java  |  4 +-
 .../event/AbstractPrintLogEventSender.java      | 63 ++++++++++++++++++++
 .../logging/event/PrintWriterEventSender.java   | 34 ++---------
 .../cxf/ext/logging/slf4j/Slf4jEventSender.java | 27 +++++----
 .../logging/slf4j/Slf4jNoMdcEventSender.java    | 49 +++++++++++++++
 .../apache/cxf/systest/jaxrs/BookServer.java    |  3 +-
 7 files changed, 136 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/5022be0c/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingInInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingInInterceptor.java
b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingInInterceptor.java
index 80dafee..87494e4 100644
--- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingInInterceptor.java
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingInInterceptor.java
@@ -30,7 +30,7 @@ import org.apache.cxf.ext.logging.event.DefaultLogEventMapper;
 import org.apache.cxf.ext.logging.event.LogEvent;
 import org.apache.cxf.ext.logging.event.LogEventSender;
 import org.apache.cxf.ext.logging.event.PrintWriterEventSender;
-import org.apache.cxf.ext.logging.slf4j.Slf4jEventSender;
+import org.apache.cxf.ext.logging.slf4j.Slf4jNoMdcEventSender;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.io.CachedWriter;
@@ -59,7 +59,7 @@ public class LoggingInInterceptor extends AbstractLoggingInterceptor {
     
     
     public LoggingInInterceptor() {
-        this(new Slf4jEventSender());
+        this(new Slf4jNoMdcEventSender());
     }
     public LoggingInInterceptor(LogEventSender sender) {
         super(Phase.PRE_INVOKE, sender);

http://git-wip-us.apache.org/repos/asf/cxf/blob/5022be0c/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingOutInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingOutInterceptor.java
b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingOutInterceptor.java
index dffe268..d5281e4 100644
--- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingOutInterceptor.java
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingOutInterceptor.java
@@ -31,7 +31,7 @@ import org.apache.cxf.ext.logging.event.DefaultLogEventMapper;
 import org.apache.cxf.ext.logging.event.LogEvent;
 import org.apache.cxf.ext.logging.event.LogEventSender;
 import org.apache.cxf.ext.logging.event.PrintWriterEventSender;
-import org.apache.cxf.ext.logging.slf4j.Slf4jEventSender;
+import org.apache.cxf.ext.logging.slf4j.Slf4jNoMdcEventSender;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.StaxOutInterceptor;
 import org.apache.cxf.io.CacheAndWriteOutputStream;
@@ -47,7 +47,7 @@ import org.apache.cxf.phase.Phase;
 public class LoggingOutInterceptor extends AbstractLoggingInterceptor {
 
     public LoggingOutInterceptor() {
-        this(new Slf4jEventSender());
+        this(new Slf4jNoMdcEventSender());
     }
     public LoggingOutInterceptor(PrintWriter w) {
         this(new PrintWriterEventSender(w));

http://git-wip-us.apache.org/repos/asf/cxf/blob/5022be0c/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/AbstractPrintLogEventSender.java
----------------------------------------------------------------------
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/AbstractPrintLogEventSender.java
b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/AbstractPrintLogEventSender.java
new file mode 100644
index 0000000..79262b7
--- /dev/null
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/AbstractPrintLogEventSender.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.ext.logging.event;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.common.util.StringUtils;
+
+/**
+ *
+ */
+public abstract class AbstractPrintLogEventSender implements LogEventSender {
+    
+    protected StringBuilder prepareBuilder(StringBuilder b, LogEvent event) {
+        b.append("\n");
+        put(b, "Type", event.getType().toString());
+        put(b, "Address", event.getAddress());
+        put(b, "HttpMethod", event.getHttpMethod());
+        put(b, "Content-Type", event.getContentType());
+        put(b, "ResponseCode", event.getResponseCode());
+        put(b, "ExchangeId", event.getExchangeId());
+        put(b, "MessageId", event.getMessageId());
+        if (event.getServiceName() != null) {
+            put(b, "ServiceName", localPart(event.getServiceName()));
+            put(b, "PortName", localPart(event.getPortName()));
+            put(b, "PortTypeName", localPart(event.getPortTypeName()));
+        }
+        if (event.getFullContentFile() != null) {
+            put(b, "FullContentFile", event.getFullContentFile().getAbsolutePath());
+        }
+        put(b, "Headers", event.getHeaders().toString());
+        if (!StringUtils.isEmpty(event.getPayload())) {
+            put(b, "Payload", event.getPayload());
+        }
+        return b;
+    }
+    protected String localPart(QName name) {
+        return name == null ? null : name.getLocalPart();
+    }
+
+    protected void put(StringBuilder b, String key, String value) {
+        if (value != null) {
+            b.append("    ").append(key).append(": ").append(value).append("\n");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5022be0c/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/PrintWriterEventSender.java
----------------------------------------------------------------------
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/PrintWriterEventSender.java
b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/PrintWriterEventSender.java
index d618028..cd94975 100644
--- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/PrintWriterEventSender.java
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/PrintWriterEventSender.java
@@ -22,12 +22,10 @@ package org.apache.cxf.ext.logging.event;
 import java.io.PrintWriter;
 import java.time.Instant;
 
-import javax.xml.namespace.QName;
-
 /**
  *
  */
-public class PrintWriterEventSender implements LogEventSender {
+public class PrintWriterEventSender extends AbstractPrintLogEventSender {
     PrintWriter writer;
 
     public PrintWriterEventSender(PrintWriter writer) {
@@ -43,35 +41,11 @@ public class PrintWriterEventSender implements LogEventSender {
     @Override
     public void send(LogEvent event) {
         StringBuilder b = new StringBuilder();
-
-        b.append(Instant.now().toString()).append(" - PrintWriterEventSender\n");
-        put(b, "type", event.getType().toString());
-        put(b, "address", event.getAddress());
-        put(b, "content-type", event.getContentType());
-        put(b, "encoding", event.getEncoding());
-        put(b, "exchangeId", event.getExchangeId());
-        put(b, "httpMethod", event.getHttpMethod());
-        put(b, "messageId", event.getMessageId());
-        put(b, "responseCode", event.getResponseCode());
-        put(b, "serviceName", localPart(event.getServiceName()));
-        put(b, "portName", localPart(event.getPortName()));
-        put(b, "portTypeName", localPart(event.getPortTypeName()));
-        if (event.getFullContentFile() != null) {
-            put(b, "fullContentFile", event.getFullContentFile().getAbsolutePath());
-        }
-        put(b, "headers", event.getHeaders().toString());
+        b.append(Instant.now().toString()).append(" - PrintWriterEventSender");
+        prepareBuilder(b, event);
         synchronized (writer) {
             writer.print(b.toString());
-            writer.println(event.getPayload());
-        }
-    }
-    protected String localPart(QName name) {
-        return name == null ? null : name.getLocalPart();
-    }
-
-    protected void put(StringBuilder b, String key, String value) {
-        if (value != null) {
-            b.append("    ").append(key).append(": ").append(value).append("\n");
         }
     }
+    
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/5022be0c/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/slf4j/Slf4jEventSender.java
----------------------------------------------------------------------
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/slf4j/Slf4jEventSender.java
b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/slf4j/Slf4jEventSender.java
index 57795a2..c641bd7 100644
--- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/slf4j/Slf4jEventSender.java
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/slf4j/Slf4jEventSender.java
@@ -47,21 +47,22 @@ public class Slf4jEventSender implements LogEventSender {
         Logger log = LoggerFactory.getLogger(cat);
         Set<String> keys = new HashSet<>();
         try {
-            put(keys, "type", event.getType().toString());
-            put(keys, "address", event.getAddress());
-            put(keys, "content-type", event.getContentType());
-            put(keys, "encoding", event.getEncoding());
-            put(keys, "exchangeId", event.getExchangeId());
-            put(keys, "httpMethod", event.getHttpMethod());
-            put(keys, "messageId", event.getMessageId());
-            put(keys, "responseCode", event.getResponseCode());
-            put(keys, "serviceName", localPart(event.getServiceName()));
-            put(keys, "portName", localPart(event.getPortName()));
-            put(keys, "portTypeName", localPart(event.getPortTypeName()));
+            put(keys, "Type", event.getType().toString());
+            put(keys, "Address", event.getAddress());
+            put(keys, "HttpMethod", event.getHttpMethod());
+            put(keys, "Content-Type", event.getContentType());
+            put(keys, "ResponseCode", event.getResponseCode());
+            put(keys, "ExchangeId", event.getExchangeId());
+            put(keys, "MessageId", event.getMessageId());
+            if (event.getServiceName() != null) {
+                put(keys, "ServiceName", localPart(event.getServiceName()));
+                put(keys, "PortName", localPart(event.getPortName()));
+                put(keys, "PortTypeName", localPart(event.getPortTypeName()));
+            }
             if (event.getFullContentFile() != null) {
-                put(keys, "fullContentFile", event.getFullContentFile().getAbsolutePath());
+                put(keys, "FullContentFile", event.getFullContentFile().getAbsolutePath());
             }
-            put(keys, "headers", event.getHeaders().toString());
+            put(keys, "Headers", event.getHeaders().toString());
             log.info(getLogMessage(event));
         } finally {
             for (String key : keys) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/5022be0c/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/slf4j/Slf4jNoMdcEventSender.java
----------------------------------------------------------------------
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/slf4j/Slf4jNoMdcEventSender.java
b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/slf4j/Slf4jNoMdcEventSender.java
new file mode 100644
index 0000000..e61e64f
--- /dev/null
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/slf4j/Slf4jNoMdcEventSender.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.ext.logging.slf4j;
+
+import org.apache.cxf.ext.logging.event.AbstractPrintLogEventSender;
+import org.apache.cxf.ext.logging.event.LogEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Slf4jNoMdcEventSender extends AbstractPrintLogEventSender {
+    private final String logCategory;
+
+    public Slf4jNoMdcEventSender(String logCategory) {
+        this.logCategory = logCategory;
+    }
+
+    public Slf4jNoMdcEventSender() {
+        this(null);
+    }
+
+    @Override
+    public void send(LogEvent event) {
+        String cat = logCategory != null ? logCategory
+            : "org.apache.cxf.services." + event.getPortTypeName().getLocalPart() + "." +
event.getType();
+        Logger log = LoggerFactory.getLogger(cat);
+        
+        StringBuilder b = new StringBuilder();
+        prepareBuilder(b, event);
+        log.info(b.toString());
+    }
+
+    
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/5022be0c/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
index 13f497a..3418ad4 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
@@ -53,6 +53,7 @@ import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.util.PropertyUtils;
 import org.apache.cxf.ext.logging.LoggingInInterceptor;
+import org.apache.cxf.ext.logging.LoggingOutInterceptor;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.Interceptor;
@@ -129,7 +130,7 @@ public class BookServer extends AbstractBusTestServerBase {
         List<Interceptor<? extends Message>> inInts = new ArrayList<Interceptor<?
extends Message>>();
         inInts.add(new CustomInFaultyInterceptor());
         inInts.add(new LoggingInInterceptor());
-
+        inInts.add(new LoggingOutInterceptor());
         sf.setInInterceptors(inInts);
         List<Interceptor<? extends Message>> outInts = new ArrayList<Interceptor<?
extends Message>>();
         outInts.add(new CustomOutInterceptor());


Mime
View raw message