Repository: logging-log4j2
Updated Branches:
  refs/heads/master caf8347a2 -> e38df78e8


LOG4J-1724 Ensure that GelfLayout is still garbage-free when no substitution


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

Branch: refs/heads/master
Commit: e38df78e876b43cbd9f8c612e8f434768d690ee4
Parents: caf8347
Author: Mikael Ståldal <mikael.stal...@magine.com>
Authored: Mon Jan 9 10:11:03 2017 +0100
Committer: Mikael Ståldal <mikael.stal...@magine.com>
Committed: Mon Jan 9 10:11:03 2017 +0100

----------------------------------------------------------------------
 .../org/apache/logging/log4j/core/layout/GelfLayout.java     | 8 +++++++-
 log4j-core/src/test/resources/gcFreeLogging.xml              | 4 +++-
 src/site/xdoc/manual/garbagefree.xml                         | 3 ++-
 3 files changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e38df78e/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
index b5a7ff4..0c757aa 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
@@ -352,7 +352,9 @@ public final class GelfLayout extends AbstractStringLayout {
                 builder.append(QU);
                 JsonUtils.quoteAsString(additionalField.getKey(), builder);
                 builder.append("\":\"");
-                final String value = strSubstitutor.replace(event, 
additionalField.getValue());
+                final String value = 
valueNeedsLookup(additionalField.getValue())
+                    ? strSubstitutor.replace(event, additionalField.getValue())
+                    : additionalField.getValue();
                 JsonUtils.quoteAsString(toNullSafeString(value), builder);
                 builder.append(QC);
             }
@@ -390,6 +392,10 @@ public final class GelfLayout extends AbstractStringLayout 
{
         return builder;
     }
 
+    private static boolean valueNeedsLookup(final String value) {
+        return value != null && value.contains("${");
+    }
+
     private static final TriConsumer<String, Object, StringBuilder> 
WRITE_KEY_VALUES_INTO = new TriConsumer<String, Object, StringBuilder>() {
         @Override
         public void accept(final String key, final Object value, final 
StringBuilder stringBuilder) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e38df78e/log4j-core/src/test/resources/gcFreeLogging.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/gcFreeLogging.xml 
b/log4j-core/src/test/resources/gcFreeLogging.xml
index 0066045..380c128 100644
--- a/log4j-core/src/test/resources/gcFreeLogging.xml
+++ b/log4j-core/src/test/resources/gcFreeLogging.xml
@@ -66,7 +66,9 @@
       </PatternLayout>
     </MemoryMappedFile>
     <RandomAccessFile name="RandomAccessFileGelf" 
fileName="target/gcfree.json" immediateFlush="false" append="false">
-       <GelfLayout compressionType="OFF"/>
+       <GelfLayout compressionType="OFF">
+         <KeyValuePair key="foo" value="FOO"/>
+       </GelfLayout>
     </RandomAccessFile>
   </Appenders>
   <Loggers>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e38df78e/src/site/xdoc/manual/garbagefree.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/garbagefree.xml 
b/src/site/xdoc/manual/garbagefree.xml
index 054a0e0..fe6c681 100644
--- a/src/site/xdoc/manual/garbagefree.xml
+++ b/src/site/xdoc/manual/garbagefree.xml
@@ -183,7 +183,8 @@
           <h4>Supported Layouts</h4>
 
           <h5>GelfLayout</h5>
-          <p>GelfLayout is garbage-free when used with 
compressionType="OFF".</p>
+          <p>GelfLayout is garbage-free when used with compressionType="OFF",
+            as long as no additional field contains '${' (variable 
substitution).</p>
 
           <h5>PatternLayout</h5>
           <p>

Reply via email to