logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1557491 - in /logging/log4j/log4j2/trunk: log4j-core/src/main/java/org/apache/logging/log4j/core/config/ log4j-core/src/test/java/org/apache/logging/log4j/core/ log4j-core/src/test/resources/ src/changes/
Date Sun, 12 Jan 2014 03:56:49 GMT
Author: rgoers
Date: Sun Jan 12 03:56:49 2014
New Revision: 1557491

URL: http://svn.apache.org/r1557491
Log:
LOG4J2-398 - Configure properties and setup Interpolator before processing rest of configuration.

Added:
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerDateTest.java
      - copied, changed from r1557479, logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/HostNameTest.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j-date.xml
      - copied, changed from r1557473, logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j-test1.xml
Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java?rev=1557491&r1=1557490&r2=1557491&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
Sun Jan 12 03:56:49 2014
@@ -243,22 +243,28 @@ public class BaseConfiguration extends A
     protected void doConfigure() {
         boolean setRoot = false;
         boolean setLoggers = false;
-        for (final Node child : rootNode.getChildren()) {
-            createConfiguration(child, null);
-            if (child.getObject() == null) {
-                continue;
+        if (rootNode.hasChildren() && rootNode.getChildren().get(0).getName().equalsIgnoreCase("Properties"))
{
+            Node first = rootNode.getChildren().get(0);
+            createConfiguration(first, null);
+            if (first.getObject() != null) {
+                subst.setVariableResolver((StrLookup) first.getObject());
             }
+        } else {
+            final Map<String, String> map = (Map<String, String>) componentMap.get(CONTEXT_PROPERTIES);
+            final StrLookup lookup = map == null ? null : new MapLookup(map);
+            subst.setVariableResolver(new Interpolator(lookup));
+        }
+
+        for (final Node child : rootNode.getChildren()) {
             if (child.getName().equalsIgnoreCase("Properties")) {
                 if (tempLookup == subst.getVariableResolver()) {
-                    subst.setVariableResolver((StrLookup) child.getObject());
-                } else {
                     LOGGER.error("Properties declaration must be the first element in the
configuration");
                 }
                 continue;
-            } else if (tempLookup == subst.getVariableResolver()) {
-                final Map<String, String> map = (Map<String, String>) componentMap.get(CONTEXT_PROPERTIES);
-                final StrLookup lookup = map == null ? null : new MapLookup(map);
-                subst.setVariableResolver(new Interpolator(lookup));
+            }
+            createConfiguration(child, null);
+            if (child.getObject() == null) {
+                continue;
             }
             if (child.getName().equalsIgnoreCase("Appenders")) {
                 appenders = (ConcurrentMap<String, Appender>) child.getObject();

Copied: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerDateTest.java
(from r1557479, logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/HostNameTest.java)
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerDateTest.java?p2=logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerDateTest.java&p1=logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/HostNameTest.java&r1=1557479&r2=1557491&rev=1557491&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/HostNameTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerDateTest.java
Sun Jan 12 03:56:49 2014
@@ -17,6 +17,7 @@
 package org.apache.logging.log4j.core;
 
 import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.appender.FileAppender;
 import org.apache.logging.log4j.core.appender.RollingFileAppender;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
@@ -29,6 +30,7 @@ import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import java.util.Calendar;
 import java.util.List;
 import java.util.Map;
 
@@ -38,13 +40,11 @@ import static org.junit.Assert.assertTru
 /**
  *
  */
-public class HostNameTest {
+public class LoggerDateTest {
 
-    private static final String CONFIG = "log4j-test2.xml";
+    private static final String CONFIG = "log4j-date.xml";
     private static Configuration config;
-    private static ListAppender app;
-    private static ListAppender host;
-    private static RollingFileAppender hostFile;
+    private static FileAppender fileApp;
     private static LoggerContext ctx;
 
     @BeforeClass
@@ -64,39 +64,18 @@ public class HostNameTest {
     public void before() {
         config = ctx.getConfiguration();
         for (final Map.Entry<String, Appender> entry : config.getAppenders().entrySet())
{
-            if (entry.getKey().equals("List")) {
-                app = (ListAppender) entry.getValue();
-            } else if (entry.getKey().equals("HostTest")) {
-                host = (ListAppender) entry.getValue();
-            } else if (entry.getKey().equals("HostFile")) {
-                hostFile = (RollingFileAppender) entry.getValue();
+            if (entry.getKey().equals("File")) {
+                fileApp = (FileAppender) entry.getValue();
             }
         }
-        assertNotNull("No Host FileAppender", hostFile);
-        app.clear();
-        host.clear();
+        assertNotNull("No FileAppender", fileApp);
     }
 
 
     @Test
-    public void testHostname() {
-        final org.apache.logging.log4j.Logger testLogger = LogManager.getLogger("org.apache.logging.log4j.hosttest");
-        testLogger.debug("Hello, {}", "World");
-        final List<String> msgs = host.getMessages();
-        assertTrue("Incorrect number of events. Expected 1, actual " + msgs.size(), msgs.size()
== 1);
-        String expected = NetUtils.getLocalHostname() + Constants.LINE_SEP;
-        assertTrue("Incorrect hostname - expected " + expected + " actual - " + msgs.get(0),
-            msgs.get(0).endsWith(expected));
-        assertNotNull("No Host FileAppender file name", hostFile.getFileName());
-        expected = "target/" + NetUtils.getLocalHostname() + ".log";
-        String name = hostFile.getFileName();
-        assertTrue("Incorrect HostFile FileAppender file name - expected " + expected + "
actual - " + name,
-            name.equals(expected));
-        name = hostFile.getFilePattern();
-        assertNotNull("No file pattern", name);
-        expected = "target/" + NetUtils.getLocalHostname() + "-%d{MM-dd-yyyy}-%i.log";
-        assertTrue("Incorrect HostFile FileAppender file pattern - expected " + expected
+ " actual - " + name,
-            name.equals(expected));
-
+    public void testFileName() {
+        String name = fileApp.getFileName();
+        int year = Calendar.getInstance().get(Calendar.YEAR);
+        assertTrue("Date was not substituted: " + name, name.contains(Integer.toString(year)));
     }
 }

Copied: logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j-date.xml (from r1557473,
logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j-test1.xml)
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j-date.xml?p2=logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j-date.xml&p1=logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j-test1.xml&r1=1557473&r2=1557491&rev=1557491&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j-test1.xml (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j-date.xml Sun Jan 12 03:56:49
2014
@@ -17,35 +17,19 @@
 
 -->
 <Configuration status="warn" name="XMLConfigTest" packages="org.apache.logging.log4j.test">
-  <Properties>
-    <Property name="filename">target/test.log</Property>
-  </Properties>
-  <ThresholdFilter level="debug"/>
 
   <Appenders>
-    <Console name="STDOUT">
-      <PatternLayout pattern="%m%n"/>
-    </Console>
-    <File name="File" fileName="${filename}" bufferedIO="false">
+    <File name="File" fileName="target/${date:yyyy-MM-dd HHmmss}.log" bufferedIO="false">
       <PatternLayout>
         <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
       </PatternLayout>
     </File>
-    <List name="List">
-      <Filters>
-        <ThresholdFilter level="error"/>
-      </Filters>
-    </List>
+    <Console name="STDOUT">
+      <PatternLayout pattern="%m%n"/>
+    </Console>
   </Appenders>
 
   <Loggers>
-    <Logger name="org.apache.logging.log4j.test1" level="debug" additivity="false">
-        <ThreadContextMapFilter>
-          <KeyValuePair key="test" value="123"/>
-        </ThreadContextMapFilter>
-      <AppenderRef ref="STDOUT"/>
-    </Logger>>
-
     <Logger name="org.apache.logging.log4j.test2" level="debug" additivity="false">
       <AppenderRef ref="File"/>
     </Logger>>

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1557491&r1=1557490&r2=1557491&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sun Jan 12 03:56:49 2014
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-RC1" date="2013-MM-DD" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-398" dev="rgoers" type="fix">
+        Configure properties and setup Interpolator before processing rest of configuration.
+      </action>
       <action issue="LOG4J2-481" dev="rgoers" type="update" due-to="Matt Sicker">
         Add Stream interface to Loggers.
       </action>



Mime
View raw message