logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1479044 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/layout/ core/src/main/java/org/apache/logging/log4j/core/lookup/ core/src/test/java/org/apache/logging/log4j/core/config/ core/src/test/resources/ s...
Date Sat, 04 May 2013 06:40:16 GMT
Author: rgoers
Date: Sat May  4 06:40:16 2013
New Revision: 1479044

URL: http://svn.apache.org/r1479044
Log:
LOG4J2-192 - Add support for interpolating Environment variables when processing the configuration.

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/lookup/Interpolator.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
    logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-config.xml
    logging/log4j/log4j2/trunk/src/changes/changes.xml

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=1479044&r1=1479043&r2=1479044&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
Sat May  4 06:40:16 2013
@@ -126,6 +126,10 @@ public final class PatternLayout extends
         formatters = parser.parse(pattern);
     }
 
+    public String getConversionPattern() {
+        return conversionPattern;
+    }
+
     /**
      * PatternLayout's content format is specified by:<p/>
      * Key: "structured" Value: "false"<p/>

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java?rev=1479044&r1=1479043&r2=1479044&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java
Sat May  4 06:40:16 2013
@@ -56,9 +56,13 @@ public class Interpolator implements Str
         }
     }
 
+    /**
+     * Create the default Interpolator using only Lookups that work without an event.
+     */
     public Interpolator() {
         this.defaultLookup = new MapLookup(new HashMap<String, String>());
         lookups.put("sys", new SystemPropertiesLookup());
+        lookups.put("env", new EnvironmentLookup());
     }
 
      /**

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java?rev=1479044&r1=1479043&r2=1479044&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
Sat May  4 06:40:16 2013
@@ -21,9 +21,12 @@ import org.apache.logging.log4j.LogManag
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.filter.CompositeFilter;
 
+import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.apache.logging.log4j.test.appender.ListAppender;
 import org.junit.Test;
 
 import java.io.File;
@@ -181,6 +184,32 @@ public class TestConfigurator {
             config.getName(), NullConfiguration.NULL_NAME.equals(config.getName()));
     }
 
+
+    @Test
+    public void testEnvironment() throws Exception {
+        final LoggerContext ctx = Configurator.initialize("-config", null, (String) null);
+        final Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
+        Configuration config = ctx.getConfiguration();
+        assertNotNull("No configuration", config);
+        assertTrue("Incorrect Configuration. Expected " + CONFIG_NAME + " but found " + config.getName(),
+            CONFIG_NAME.equals(config.getName()));
+        final Map<String, Appender<?>> map = config.getAppenders();
+        assertNotNull("No Appenders", map != null && map.size() > 0);
+        Appender<?> app = null;
+        for (Map.Entry<String, Appender<?>> entry: map.entrySet()) {
+            if (entry.getKey().equals("List2")) {
+                app = entry.getValue();
+            }
+        }
+        assertNotNull("No ListAppender named List2", app);
+        Layout layout = app.getLayout();
+        assertNotNull("Appender List2 does not have a Layout", layout);
+        assertTrue("Appender List2 is not configured with a PatternLayout", layout instanceof
PatternLayout);
+        String pattern = ((PatternLayout) layout).getConversionPattern();
+        assertNotNull("No conversion pattern for List2 PatternLayout", pattern);
+        assertFalse("Environment variable was not substituted", pattern.startsWith("${env:PATH}"));
+    }
+
     @Test
     public void testNoLoggers() throws Exception {
         final LoggerContext ctx = Configurator.initialize("Test1", null, "bad/log4j-loggers.xml");

Modified: logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-config.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-config.xml?rev=1479044&r1=1479043&r2=1479044&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-config.xml (original)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-config.xml Sat May  4 06:40:16
2013
@@ -22,6 +22,9 @@
     <Console name="STDOUT">
       <PatternLayout pattern="%m%n"/>
     </Console>
+    <List name="List2">
+      <PatternLayout pattern="${env:PATH} %m%n"/>
+    </List>
     <List name="List">
     </List>
   </appenders>

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1479044&r1=1479043&r2=1479044&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sat May  4 06:40:16 2013
@@ -23,6 +23,9 @@
 
   <body>
     <release version="2.0-beta6" date="@TBD@" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-192" dev="rgoers" type="fix">
+        Add support for interpolating Environment variables when processing the configuration.
+      </action>
       <action issue="LOG4J2-235" dev="rpopma" type="fix" due-to="Sebastian Oerding">
         Removed dependency on tools jar from core module, made jconsole dependency optional.
       </action>



Mime
View raw message