cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cxf git commit: CXF-7129: Provide an optional HTrace Logging receiver, prettified the default output and made the implementation Java 7 compatible.
Date Mon, 27 Feb 2017 20:18:57 GMT
Repository: cxf
Updated Branches:
  refs/heads/master c5c2f87e4 -> 7c3a8b02a


CXF-7129: Provide an optional HTrace Logging receiver, prettified the default output and made
the implementation Java 7 compatible.


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

Branch: refs/heads/master
Commit: 7c3a8b02a62db3bcc5c3a1895e9f30bc4fa3821a
Parents: c5c2f87
Author: reta <drreta@gmail.com>
Authored: Mon Feb 27 12:17:09 2017 -0500
Committer: reta <drreta@gmail.com>
Committed: Mon Feb 27 14:53:42 2017 -0500

----------------------------------------------------------------------
 .../tracing/htrace/ext/LoggingSpanReceiver.java | 53 +++++++++++++++-----
 1 file changed, 41 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/7c3a8b02/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/ext/LoggingSpanReceiver.java
----------------------------------------------------------------------
diff --git a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/ext/LoggingSpanReceiver.java
b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/ext/LoggingSpanReceiver.java
index 332b385..2fdafd6 100644
--- a/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/ext/LoggingSpanReceiver.java
+++ b/integration/tracing/tracing-htrace/src/main/java/org/apache/cxf/tracing/htrace/ext/LoggingSpanReceiver.java
@@ -20,10 +20,10 @@
 package org.apache.cxf.tracing.htrace.ext;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Map;
-import java.util.function.Function;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -44,9 +44,23 @@ public class LoggingSpanReceiver extends SpanReceiver {
     public static final String LOG_LEVEL_INFO = Level.INFO.getName();
     public static final String LOG_LEVEL_WARN = Level.WARNING.getName();
 
+    private interface Stringifier<T> {
+        String toString(T value);
+    }
+    
     private static final Logger LOG = LogUtils.getL7dLogger(LoggingSpanReceiver.class);
     private final Level level;
 
+    private final Stringifier<TimelineAnnotation> timelineStringifier = new Stringifier<TimelineAnnotation>()
{
+        @Override
+        public String toString(TimelineAnnotation annotation) {
+            final StringBuilder sb = new StringBuilder();
+            append(sb, "time", annotation.getTime());
+            append(sb, "message", annotation.getMessage(), true);
+            return "[" + sb.toString() + "]";
+        }
+    };
+
     public LoggingSpanReceiver(HTraceConfiguration conf) {
         level = Level.parse(conf.get(LOG_LEVEL_KEY, LOG_LEVEL_DEBUG));
     }
@@ -60,6 +74,7 @@ public class LoggingSpanReceiver extends SpanReceiver {
     public void close() throws IOException {
     }
     
+    
     /**
      * Sample log statements:
      * 
@@ -73,12 +88,6 @@ public class LoggingSpanReceiver extends SpanReceiver {
      *   description="GET http://localhost:8282/rest/api/people" parents=[] kvs=[] timelines=[]
      */
     
-    private String toString(TimelineAnnotation annotation) {
-        final StringBuilder sb = new StringBuilder();
-        append(sb, "time", annotation.getTime());
-        append(sb, "message", annotation.getMessage(), true);
-        return sb.toString();
-    }
     
     private String toString(Span span) {
         final StringBuilder sb = new StringBuilder();
@@ -106,12 +115,12 @@ public class LoggingSpanReceiver extends SpanReceiver {
         
         append(sb, "parents", span.getParents());
         append(sb, "kvs", span.getKVAnnotations());
-        append(sb, "timelines", span.getTimelineAnnotations(), t -> "[" + toString(t)
+ "]");
+        append(sb, "timelines", span.getTimelineAnnotations(), timelineStringifier);
         
         return sb.toString();
     }
 
-    private<T> void append(StringBuilder sb, String key, Map<String, String>
values) {
+    private void append(StringBuilder sb, String key, Map<String, String> values) {
         final StringBuilder inner = new StringBuilder();
         
         for (final Map.Entry<String, String> entry : values.entrySet()) {
@@ -121,12 +130,12 @@ public class LoggingSpanReceiver extends SpanReceiver {
         append(sb, key, inner.insert(0, "[").append("]").toString());
     }
     
-    private<T> void append(StringBuilder sb, String key, Collection<T> values,
Function<T, String> stringifyer) {
-        append(sb, key, Arrays.toString(values.stream().map(stringifyer::apply).toArray(String[]::new)));
+    private<T> void append(StringBuilder sb, String key, Collection<T> values,
Stringifier<T> stringifier) {
+        append(sb, key, toString(values, stringifier));
     }
     
     private<T> void append(StringBuilder sb, String key, T[] values) {
-        append(sb, key, Arrays.toString(Arrays.stream(values).map(T::toString).toArray(String[]::new)));
+        append(sb, key, toString(values));
     }
     
     private void append(StringBuilder sb, String key, long value) {
@@ -152,6 +161,26 @@ public class LoggingSpanReceiver extends SpanReceiver {
         return sb.toString();
     }
     
+    private<T> String toString(Collection<T> values, Stringifier<T> stringifier)
{
+        final Collection<String> converted = new ArrayList<>();
+        
+        for (final T value: values) {
+            converted.add(stringifier.toString(value));
+        }
+        
+        return Arrays.toString(converted.toArray());
+    }
+    
+    private<T> String toString(T[] values) {
+        final Collection<String> converted = new ArrayList<>();
+        
+        for (final T value: values) {
+            converted.add(value.toString());
+        }
+        
+        return Arrays.toString(converted.toArray());
+    }
+    
     private void quote(StringBuilder sb, String value, boolean quoted) {
         if (quoted) {
             sb.append("\"");


Mime
View raw message