felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r957826 - in /felix/branches/karaf-1.6.x/karaf: assembly/src/main/distribution/text/etc/ shell/log/src/main/java/org/apache/felix/karaf/shell/log/ shell/log/src/main/java/org/apache/felix/karaf/shell/log/layout/
Date Fri, 25 Jun 2010 07:39:18 GMT
Author: gnodet
Date: Fri Jun 25 07:39:18 2010
New Revision: 957826

URL: http://svn.apache.org/viewvc?rev=957826&view=rev
Log:
FELIX-2443: MDC information on logging events can't be displayed in the console

Modified:
    felix/branches/karaf-1.6.x/karaf/assembly/src/main/distribution/text/etc/org.apache.felix.karaf.log.cfg
    felix/branches/karaf-1.6.x/karaf/shell/log/src/main/java/org/apache/felix/karaf/shell/log/VmLogAppender.java
    felix/branches/karaf-1.6.x/karaf/shell/log/src/main/java/org/apache/felix/karaf/shell/log/layout/PatternParser.java

Modified: felix/branches/karaf-1.6.x/karaf/assembly/src/main/distribution/text/etc/org.apache.felix.karaf.log.cfg
URL: http://svn.apache.org/viewvc/felix/branches/karaf-1.6.x/karaf/assembly/src/main/distribution/text/etc/org.apache.felix.karaf.log.cfg?rev=957826&r1=957825&r2=957826&view=diff
==============================================================================
--- felix/branches/karaf-1.6.x/karaf/assembly/src/main/distribution/text/etc/org.apache.felix.karaf.log.cfg
(original)
+++ felix/branches/karaf-1.6.x/karaf/assembly/src/main/distribution/text/etc/org.apache.felix.karaf.log.cfg
Fri Jun 25 07:39:18 2010
@@ -19,4 +19,4 @@
 
 #
 size = 500
-pattern = %d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n
+pattern = %d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %X{bundle.id} -
%X{bundle.name} - %X{bundle.version} | %m%n

Modified: felix/branches/karaf-1.6.x/karaf/shell/log/src/main/java/org/apache/felix/karaf/shell/log/VmLogAppender.java
URL: http://svn.apache.org/viewvc/felix/branches/karaf-1.6.x/karaf/shell/log/src/main/java/org/apache/felix/karaf/shell/log/VmLogAppender.java?rev=957826&r1=957825&r2=957826&view=diff
==============================================================================
--- felix/branches/karaf-1.6.x/karaf/shell/log/src/main/java/org/apache/felix/karaf/shell/log/VmLogAppender.java
(original)
+++ felix/branches/karaf-1.6.x/karaf/shell/log/src/main/java/org/apache/felix/karaf/shell/log/VmLogAppender.java
Fri Jun 25 07:39:18 2010
@@ -38,6 +38,7 @@ public class VmLogAppender implements Pa
 
     public void doAppend(PaxLoggingEvent event) {
         if (events != null) {
+            event.getProperties(); // ensure MDC properties are copied
             events.add(event);
         }
     }

Modified: felix/branches/karaf-1.6.x/karaf/shell/log/src/main/java/org/apache/felix/karaf/shell/log/layout/PatternParser.java
URL: http://svn.apache.org/viewvc/felix/branches/karaf-1.6.x/karaf/shell/log/src/main/java/org/apache/felix/karaf/shell/log/layout/PatternParser.java?rev=957826&r1=957825&r2=957826&view=diff
==============================================================================
--- felix/branches/karaf-1.6.x/karaf/shell/log/src/main/java/org/apache/felix/karaf/shell/log/layout/PatternParser.java
(original)
+++ felix/branches/karaf-1.6.x/karaf/shell/log/src/main/java/org/apache/felix/karaf/shell/log/layout/PatternParser.java
Fri Jun 25 07:39:18 2010
@@ -18,7 +18,9 @@ package org.apache.felix.karaf.shell.log
 
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.util.Arrays;
 import java.util.Date;
+import java.util.Map;
 
 import org.apache.log4j.spi.LoggingEvent;
 import org.ops4j.pax.logging.spi.PaxLocationInfo;
@@ -344,12 +346,12 @@ public class PatternParser {
       pc = new BasicPatternConverter(formattingInfo, NDC_CONVERTER);
       //LogLog.debug("NDC converter.");
       currentLiteral.setLength(0);
-      break;
+      break;*/
     case 'X':
       String xOpt = extractOption();
       pc = new MDCPatternConverter(formattingInfo, xOpt);
       currentLiteral.setLength(0);
-      break;*/
+      break;
     default:
       //LogLog.error("Unexpected char [" +c+"] at position "+i+" in conversion patterrn.");
       pc = new LiteralPatternConverter(currentLiteral.toString());
@@ -523,5 +525,43 @@ public class PatternParser {
       return event.getLoggerName();
     }
   }
+
+  private class MDCPatternConverter extends PatternConverter {
+    String key;
+
+    MDCPatternConverter(FormattingInfo formattingInfo, String key) {
+      super(formattingInfo);
+      this.key = key;
+    }
+
+    public
+    String convert(PaxLoggingEvent event) {
+        if (key == null) {
+            StringBuffer buf = new StringBuffer("{");
+            Map properties = event.getProperties();
+            if (properties.size() > 0) {
+              Object[] keys = properties.keySet().toArray();
+              Arrays.sort(keys);
+              for (int i = 0; i < keys.length; i++) {
+                  buf.append('{');
+                  buf.append(keys[i]);
+                  buf.append(',');
+                  buf.append(properties.get(keys[i]));
+                  buf.append('}');
+              }
+            }
+            buf.append('}');
+            return buf.toString();
+        } else {
+          Object val = event.getProperties().get(key);
+          if(val == null) {
+              return null;
+          } else {
+              return val.toString();
+          }
+        }
+    }
+
+  }
 }
 



Mime
View raw message