cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject cxf git commit: [CXF-7254] Allow to use vebose logging in feature and config. Refactoring
Date Fri, 24 Feb 2017 13:38:46 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 5022be0c1 -> 65c1204ab


[CXF-7254] Allow to use vebose logging in feature and config. Refactoring


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

Branch: refs/heads/master
Commit: 65c1204abcef8720d4eb985d58e3f865e39a1da3
Parents: 5022be0
Author: Christian Schneider <chris@die-schneider.net>
Authored: Fri Feb 24 14:38:37 2017 +0100
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Fri Feb 24 14:38:37 2017 +0100

----------------------------------------------------------------------
 .../apache/cxf/ext/logging/LoggingFeature.java  |  6 ++
 .../cxf/ext/logging/LoggingInInterceptor.java   | 10 +--
 .../cxf/ext/logging/LoggingOutInterceptor.java  | 10 +--
 .../event/AbstractPrintLogEventSender.java      | 63 -------------------
 .../ext/logging/event/LogMessageFormatter.java  | 66 ++++++++++++++++++++
 .../logging/event/PrintWriterEventSender.java   | 13 +---
 .../apache/cxf/ext/logging/osgi/Activator.java  |  5 ++
 .../cxf/ext/logging/slf4j/Slf4jEventSender.java | 14 +----
 .../logging/slf4j/Slf4jNoMdcEventSender.java    | 49 ---------------
 .../logging/slf4j/Slf4jVerboseEventSender.java  | 31 +++++++++
 10 files changed, 119 insertions(+), 148 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/65c1204a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFeature.java
----------------------------------------------------------------------
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFeature.java
b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFeature.java
index 473dbe7..ce39725 100644
--- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFeature.java
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFeature.java
@@ -25,6 +25,7 @@ import org.apache.cxf.common.injection.NoJSR250Annotations;
 import org.apache.cxf.ext.logging.event.LogEventSender;
 import org.apache.cxf.ext.logging.event.PrettyLoggingFilter;
 import org.apache.cxf.ext.logging.slf4j.Slf4jEventSender;
+import org.apache.cxf.ext.logging.slf4j.Slf4jVerboseEventSender;
 import org.apache.cxf.feature.AbstractFeature;
 import org.apache.cxf.interceptor.InterceptorProvider;
 
@@ -103,4 +104,9 @@ public class LoggingFeature extends AbstractFeature {
         in.setLogMultipart(logMultipart);
         out.setLogMultipart(logMultipart);
     }
+    
+    public void setVerbose(boolean verbose) {
+        sender = verbose ? new Slf4jVerboseEventSender() : new Slf4jEventSender();
+        this.prettyFilter.setNext(sender);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/65c1204a/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 87494e4..55839ca 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
@@ -19,7 +19,6 @@
 package org.apache.cxf.ext.logging;
 
 import java.io.IOException;
-import java.io.PrintWriter;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -29,8 +28,7 @@ import org.apache.cxf.common.util.StringUtils;
 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.Slf4jNoMdcEventSender;
+import org.apache.cxf.ext.logging.slf4j.Slf4jVerboseEventSender;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.io.CachedWriter;
@@ -59,14 +57,12 @@ public class LoggingInInterceptor extends AbstractLoggingInterceptor {
     
     
     public LoggingInInterceptor() {
-        this(new Slf4jNoMdcEventSender());
+        this(new Slf4jVerboseEventSender());
     }
     public LoggingInInterceptor(LogEventSender sender) {
         super(Phase.PRE_INVOKE, sender);
     }
-    public LoggingInInterceptor(PrintWriter writer) {
-        this(new PrintWriterEventSender(writer));
-    }
+
     public Collection<PhaseInterceptor<? extends Message>> getAdditionalInterceptors()
{
         Collection<PhaseInterceptor<? extends Message>> ret = new ArrayList<>();
         ret.add(new WireTapIn(limit, threshold));

http://git-wip-us.apache.org/repos/asf/cxf/blob/65c1204a/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 d5281e4..7a0f6a6 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
@@ -21,7 +21,6 @@ package org.apache.cxf.ext.logging;
 import java.io.FilterWriter;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.io.Writer;
 
@@ -30,8 +29,7 @@ import org.apache.cxf.common.util.StringUtils;
 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.Slf4jNoMdcEventSender;
+import org.apache.cxf.ext.logging.slf4j.Slf4jVerboseEventSender;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.StaxOutInterceptor;
 import org.apache.cxf.io.CacheAndWriteOutputStream;
@@ -47,11 +45,9 @@ import org.apache.cxf.phase.Phase;
 public class LoggingOutInterceptor extends AbstractLoggingInterceptor {
 
     public LoggingOutInterceptor() {
-        this(new Slf4jNoMdcEventSender());
-    }
-    public LoggingOutInterceptor(PrintWriter w) {
-        this(new PrintWriterEventSender(w));
+        this(new Slf4jVerboseEventSender());
     }
+
     public LoggingOutInterceptor(LogEventSender sender) {
         super(Phase.PRE_STREAM, sender);
         addBefore(StaxOutInterceptor.class.getName());

http://git-wip-us.apache.org/repos/asf/cxf/blob/65c1204a/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
deleted file mode 100644
index 79262b7..0000000
--- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/AbstractPrintLogEventSender.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * 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/65c1204a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/LogMessageFormatter.java
----------------------------------------------------------------------
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/LogMessageFormatter.java
b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/LogMessageFormatter.java
new file mode 100644
index 0000000..4ec8cb1
--- /dev/null
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/event/LogMessageFormatter.java
@@ -0,0 +1,66 @@
+/**
+ * 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 final class LogMessageFormatter {
+    
+    private LogMessageFormatter() {
+    }
+    
+    public static String fomat(LogEvent event) {
+        StringBuilder b = new StringBuilder();
+        write(b, "Type", event.getType().toString());
+        write(b, "Address", event.getAddress());
+        write(b, "HttpMethod", event.getHttpMethod());
+        write(b, "Content-Type", event.getContentType());
+        write(b, "ResponseCode", event.getResponseCode());
+        write(b, "ExchangeId", event.getExchangeId());
+        write(b, "MessageId", event.getMessageId());
+        if (event.getServiceName() != null) {
+            write(b, "ServiceName", localPart(event.getServiceName()));
+            write(b, "PortName", localPart(event.getPortName()));
+            write(b, "PortTypeName", localPart(event.getPortTypeName()));
+        }
+        if (event.getFullContentFile() != null) {
+            write(b, "FullContentFile", event.getFullContentFile().getAbsolutePath());
+        }
+        write(b, "Headers", event.getHeaders().toString());
+        if (!StringUtils.isEmpty(event.getPayload())) {
+            write(b, "Payload", event.getPayload());
+        }
+        return b.toString();
+    }
+    protected static String localPart(QName name) {
+        return name == null ? null : name.getLocalPart();
+    }
+
+    protected static void write(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/65c1204a/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 cd94975..50ccb8e 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
@@ -25,26 +25,19 @@ import java.time.Instant;
 /**
  *
  */
-public class PrintWriterEventSender extends AbstractPrintLogEventSender {
+public class PrintWriterEventSender implements LogEventSender {
     PrintWriter writer;
 
     public PrintWriterEventSender(PrintWriter writer) {
         this.writer = writer;
     }
 
-    void setPrintWriter(PrintWriter w) {
-        writer = w;
-    }
-
-
     /** {@inheritDoc}*/
     @Override
     public void send(LogEvent event) {
-        StringBuilder b = new StringBuilder();
-        b.append(Instant.now().toString()).append(" - PrintWriterEventSender");
-        prepareBuilder(b, event);
         synchronized (writer) {
-            writer.print(b.toString());
+            writer.println(Instant.now().toString() + " - PrintWriterEventSender");
+            writer.print(LogMessageFormatter.fomat(event));
         }
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/65c1204a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/osgi/Activator.java
b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/osgi/Activator.java
index 510fe72..99bca6a 100644
--- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/osgi/Activator.java
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/osgi/Activator.java
@@ -67,6 +67,7 @@ public class Activator implements BundleActivator {
             LOG.info("CXF message logging feature " + (enabled ? "enabled" : "disabled"));
             Integer limit = Integer.valueOf(getValue(config, "limit", "65536"));
             Boolean pretty = Boolean.valueOf(getValue(config, "pretty", "false"));
+            Boolean verbose = Boolean.valueOf(getValue(config, "verbose", "false"));
             Long inMemThreshold = Long.valueOf(getValue(config, "inMemThresHold", "-1"));
 
             if (limit != null) {
@@ -78,6 +79,10 @@ public class Activator implements BundleActivator {
             if (pretty != null) {
                 logging.setPrettyLogging(pretty);
             }
+            
+            if (verbose != null) {
+                logging.setVerbose(verbose);
+            }
 
             if (intentReg == null) {
                 Dictionary<String, Object> properties = new Hashtable<>();

http://git-wip-us.apache.org/repos/asf/cxf/blob/65c1204a/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 c641bd7..5fb6b43 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
@@ -30,20 +30,10 @@ import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
 
 public class Slf4jEventSender implements LogEventSender {
-    private final String logCategory;
-
-    public Slf4jEventSender(String logCategory) {
-        this.logCategory = logCategory;
-    }
-
-    public Slf4jEventSender() {
-        this(null);
-    }
 
     @Override
     public void send(LogEvent event) {
-        String cat = logCategory != null ? logCategory
-            : "org.apache.cxf.services." + event.getPortTypeName().getLocalPart() + "." +
event.getType();
+        String cat = "org.apache.cxf.services." + event.getPortTypeName().getLocalPart()
+ "." + event.getType();
         Logger log = LoggerFactory.getLogger(cat);
         Set<String> keys = new HashSet<>();
         try {
@@ -76,7 +66,7 @@ public class Slf4jEventSender implements LogEventSender {
         return name == null ? null : name.getLocalPart();
     }
 
-    private String getLogMessage(LogEvent event) {
+    protected String getLogMessage(LogEvent event) {
         return event.getPayload();
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/65c1204a/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
deleted file mode 100644
index e61e64f..0000000
--- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/slf4j/Slf4jNoMdcEventSender.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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/65c1204a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/slf4j/Slf4jVerboseEventSender.java
----------------------------------------------------------------------
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/slf4j/Slf4jVerboseEventSender.java
b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/slf4j/Slf4jVerboseEventSender.java
new file mode 100644
index 0000000..7b74da3
--- /dev/null
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/slf4j/Slf4jVerboseEventSender.java
@@ -0,0 +1,31 @@
+/**
+ * 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.LogEvent;
+import org.apache.cxf.ext.logging.event.LogMessageFormatter;
+
+public class Slf4jVerboseEventSender extends Slf4jEventSender {
+
+    @Override
+    protected String getLogMessage(LogEvent event) {
+        return LogMessageFormatter.fomat(event);
+    }
+
+}


Mime
View raw message