logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1389147 - in /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core: layout/PatternLayout.java pattern/LiteralPatternConverter.java pattern/MessagePatternConverter.java pattern/PatternParser.java
Date Sun, 23 Sep 2012 21:27:17 GMT
Author: rgoers
Date: Sun Sep 23 21:27:17 2012
New Revision: 1389147

URL: http://svn.apache.org/viewvc?rev=1389147&view=rev
Log:
Move variable substitution from PatternLayout to appropriate converters to improve performance.

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java?rev=1389147&r1=1389146&r2=1389147&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java
Sun Sep 23 21:27:17 2012
@@ -109,7 +109,6 @@ public final class PatternLayout extends
         PatternParser parser = createPatternParser(config);
         formatters = parser.parse((pattern == null) ? DEFAULT_CONVERSION_PATTERN : pattern);
         handlesExceptions = parser.handlesExceptions();
-
     }
 
     /**
@@ -144,7 +143,7 @@ public final class PatternLayout extends
         if (replace != null) {
             str = replace.format(str);
         }
-        return config == null ? str : config.getSubst().replace(event, str);
+        return str;
     }
 
     /**

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java?rev=1389147&r1=1389146&r2=1389147&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java
Sun Sep 23 21:27:17 2012
@@ -17,6 +17,7 @@
 package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.Configuration;
 
 
 /**
@@ -28,33 +29,40 @@ public final class LiteralPatternConvert
      */
     private final String literal;
 
+    private final Configuration config;
+
+    private final boolean substitute;
+
     /**
      * Create a new instance.
      *
+     * @param config The Configuration.
      * @param literal string literal.
      */
-    public LiteralPatternConverter(final String literal) {
+    public LiteralPatternConverter(final Configuration config, final String literal) {
         super("Literal", "literal");
         this.literal = literal;
+        this.config = config;
+        substitute = config != null && literal.contains("${");
     }
 
     /**
      * {@inheritDoc}
      */
     public void format(final LogEvent event, final StringBuilder toAppendTo) {
-        toAppendTo.append(literal);
+        toAppendTo.append(substitute ? config.getSubst().replace(event, literal) : literal);
     }
     /**
      * {@inheritDoc}
      */
     public void format(final Object obj, final StringBuilder output) {
-        output.append(literal);
+        output.append(substitute ? config.getSubst().replace(literal) : literal);
     }
 
     /**
      * {@inheritDoc}
      */
     public void format(Object[] objects, final StringBuilder output) {
-        output.append(literal);
+        output.append(substitute ? config.getSubst().replace(literal) : literal);
     }
 }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.java?rev=1389147&r1=1389146&r2=1389147&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.java
Sun Sep 23 21:27:17 2012
@@ -17,6 +17,7 @@
 package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.message.MultiformatMessage;
 import org.apache.logging.log4j.message.Message;
@@ -30,13 +31,16 @@ public final class MessagePatternConvert
 
     private final String[] formats;
 
+    private final Configuration config;
+
     /**
      * Private constructor.
      * @param options options, may be null.
      */
-    private MessagePatternConverter(final String[] options) {
+    private MessagePatternConverter(final Configuration config, final String[] options) {
         super("Message", "message");
         formats = options;
+        this.config = config;
     }
 
     /**
@@ -45,8 +49,8 @@ public final class MessagePatternConvert
      * @param options options, may be null.
      * @return instance of pattern converter.
      */
-    public static MessagePatternConverter newInstance(final String[] options) {
-        return new MessagePatternConverter(options);
+    public static MessagePatternConverter newInstance(final Configuration config, final String[]
options) {
+        return new MessagePatternConverter(config, options);
     }
 
     /**
@@ -55,11 +59,14 @@ public final class MessagePatternConvert
     public void format(final LogEvent event, final StringBuilder toAppendTo) {
         Message msg = event.getMessage();
         if (msg != null) {
+            String result;
             if (msg instanceof MultiformatMessage) {
-                toAppendTo.append(((MultiformatMessage) msg).getFormattedMessage(formats));
+                result = ((MultiformatMessage) msg).getFormattedMessage(formats);
             } else {
-                toAppendTo.append(msg.getFormattedMessage());
+                result = msg.getFormattedMessage();
             }
+            toAppendTo.append(config != null && result.contains("${") ?
+                config.getSubst().replace(event, result) : result);
         }
     }
 }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java?rev=1389147&r1=1389146&r2=1389147&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
Sun Sep 23 21:27:17 2012
@@ -140,7 +140,7 @@ public final class PatternParser {
                 pc = (LogEventPatternConverter) converter;
                 handlesExceptions |= pc.handlesThrowable();
             } else {
-                pc = new LiteralPatternConverter("");
+                pc = new LiteralPatternConverter(config, "");
             }
 
             FormattingInfo field;
@@ -269,7 +269,7 @@ public final class PatternParser {
                             default:
 
                                 if (currentLiteral.length() != 0) {
-                                    patternConverters.add(new LiteralPatternConverter(currentLiteral.toString()));
+                                    patternConverters.add(new LiteralPatternConverter(config,
currentLiteral.toString()));
                                     formattingInfos.add(FormattingInfo.getDefault());
                                 }
 
@@ -377,7 +377,7 @@ public final class PatternParser {
 
         // while
         if (currentLiteral.length() != 0) {
-            patternConverters.add(new LiteralPatternConverter(currentLiteral.toString()));
+            patternConverters.add(new LiteralPatternConverter(config, currentLiteral.toString()));
             formattingInfos.add(FormattingInfo.getDefault());
         }
     }
@@ -515,14 +515,14 @@ public final class PatternParser {
 
             LOGGER.error(msg.toString());
 
-            patternConverters.add(new LiteralPatternConverter(currentLiteral.toString()));
+            patternConverters.add(new LiteralPatternConverter(config, currentLiteral.toString()));
             formattingInfos.add(FormattingInfo.getDefault());
         } else {
             patternConverters.add(pc);
             formattingInfos.add(formattingInfo);
 
             if (currentLiteral.length() > 0) {
-                patternConverters.add(new LiteralPatternConverter(currentLiteral.toString()));
+                patternConverters.add(new LiteralPatternConverter(config, currentLiteral.toString()));
                 formattingInfos.add(FormattingInfo.getDefault());
             }
         }



Mime
View raw message