You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by mi...@apache.org on 2016/04/18 13:37:54 UTC

[08/50] logging-log4j2 git commit: LOG4J2-1334 Jackson-based layouts somehow filter out Message.getFormat() for Log4jLogEvent. Need to set up the same filters for MutableLogEvent but don't know how... This is a workaround.

LOG4J2-1334 Jackson-based layouts somehow filter out Message.getFormat() for Log4jLogEvent. Need to set up the same filters for MutableLogEvent but don't know how... This is a workaround.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/cedf1552
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/cedf1552
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/cedf1552

Branch: refs/heads/LOG4J2-1365
Commit: cedf155230553d8c31bc669e3597b266dc3bf709
Parents: 3f395f6
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 21:49:44 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 21:49:44 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/layout/AbstractJacksonLayout.java   | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cedf1552/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
index 7cbc798..22e2d36 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
@@ -22,6 +22,8 @@ import java.nio.charset.Charset;
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.MutableLogEvent;
 import org.apache.logging.log4j.core.util.StringBuilderWriter;
 import org.apache.logging.log4j.util.Strings;
 
@@ -51,13 +53,13 @@ abstract class AbstractJacksonLayout extends AbstractStringLayout {
 
     /**
      * Formats a {@link org.apache.logging.log4j.core.LogEvent}.
-     * 
+     *
      * @param event The LogEvent.
      * @return The XML representation of the LogEvent.
      */
     @Override
     public String toSerializable(final LogEvent event) {
-        final StringBuilderWriter writer = new StringBuilderWriter();        
+        final StringBuilderWriter writer = new StringBuilderWriter();
         try {
             toSerializable(event, writer);
             return writer.toString();
@@ -68,9 +70,18 @@ abstract class AbstractJacksonLayout extends AbstractStringLayout {
         }
     }
 
+    private static LogEvent convertMutableToLog4jEvent(final LogEvent event) {
+        // TODO Jackson-based layouts have certain filters set up for Log4jLogEvent.
+        // TODO Need to set up the same filters for MutableLogEvent but don't know how...
+        // This is a workaround.
+        return event instanceof MutableLogEvent
+                ? Log4jLogEvent.deserialize(Log4jLogEvent.serialize(event, event.isIncludeLocation()))
+                : event;
+    }
+
     public void toSerializable(final LogEvent event, final Writer writer)
             throws JsonGenerationException, JsonMappingException, IOException {
-        objectWriter.writeValue(writer, event);
+        objectWriter.writeValue(writer, convertMutableToLog4jEvent(event));
         writer.write(eol);
         markEvent();
     }