Author: ggregory
Date: Sat Aug 10 03:31:49 2013
New Revision: 1512556

URL: http://svn.apache.org/r1512556
Log:
[LOG4J2-341] Enable XInclude for XML configurations.

Added:
    
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude-appenders.xml 
  (with props)
    
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude-loggers.xml   
(with props)
    logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude.xml   
(with props)
Modified:
    
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
    
logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java?rev=1512556&r1=1512555&r2=1512556&view=diff
==============================================================================
--- 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
 (original)
+++ 
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
 Sat Aug 10 03:31:49 2013
@@ -33,6 +33,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+
 import javax.xml.XMLConstants;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -99,7 +100,14 @@ public class XMLConfiguration extends Ba
             buffer = toByteArray(configStream);
             configStream.close();
             final InputSource source = new InputSource(new 
ByteArrayInputStream(buffer));
-            final DocumentBuilder builder = 
DocumentBuilderFactory.newInstance().newDocumentBuilder();
+            final DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance();
+            factory.setNamespaceAware(true);
+            try {
+                factory.setXIncludeAware(true);
+            } catch (UnsupportedOperationException e) {
+                LOGGER.warn("This DocumentBuilderFactory does not support 
XInclude: " + factory, e);
+            }
+            final DocumentBuilder builder = factory.newDocumentBuilder();
             final Document document = builder.parse(source);
             rootElement = document.getDocumentElement();
             final Map<String, String> attrs = processAttributes(rootNode, 
rootElement);

Modified: 
logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java?rev=1512556&r1=1512555&r2=1512556&view=diff
==============================================================================
--- 
logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java
 (original)
+++ 
logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java
 Sat Aug 10 03:31:49 2013
@@ -16,6 +16,19 @@
  */
 package org.apache.logging.log4j.core.config;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStreamReader;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -24,30 +37,38 @@ import org.apache.logging.log4j.core.Fil
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.filter.ThreadContextMapFilter;
 import org.apache.logging.log4j.status.StatusLogger;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
-
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.InputStreamReader;
-import java.util.Iterator;
-import java.util.Map;
-
-import static org.junit.Assert.*;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 
 /**
  *
  */
+@RunWith(Parameterized.class)
 public class XMLConfigurationTest {
 
-    private static final String CONFIG = "log4j-test1.xml";
-    private static final String LOGFILE = "target/test.log";
+    public XMLConfigurationTest(String configFile, String logFile) {
+        super();
+        this.configFile = configFile;
+        this.logFile = logFile;
+    }
+
+    private final String configFile;
+    private final String logFile ;
 
-    @BeforeClass
-    public static void setupClass() {
-        
System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+    @Parameters
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {
+                {"log4j-test1.xml", "target/test.log"}, 
+                {"log4j-xinclude.xml", "target/test.log"}});
+    }
+
+    @Before
+    public void setUp() {
+        
System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, 
configFile);
         final LoggerContext ctx = (LoggerContext) LogManager.getContext();
         final Configuration config = ctx.getConfiguration();
         if (config instanceof XMLConfiguration) {
@@ -60,8 +81,8 @@ public class XMLConfigurationTest {
         }
     }
 
-    @AfterClass
-    public static void cleanupClass() {
+    @After
+    public void tearDown() {
         
System.clearProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
         final LoggerContext ctx = (LoggerContext) LogManager.getContext();
         ctx.reconfigure();
@@ -87,22 +108,23 @@ public class XMLConfigurationTest {
         assertEquals(a.getName(), "STDOUT");
     }
 
+    @Test
     public void testConfiguredAppenders() {
         final LoggerContext ctx = (LoggerContext) LogManager.getContext();
         final Configuration c = ctx.getConfiguration();
         final Map<String, Appender<?>> apps = c.getAppenders();
         assertNotNull(apps);
-        assertEquals(apps.size(), 3);
+        assertEquals(3, apps.size());
     }
 
     @Test
     public void logToFile() throws Exception {
-        final FileOutputStream fos = new FileOutputStream(LOGFILE, false);
+        final FileOutputStream fos = new FileOutputStream(logFile, false);
         fos.flush();
         fos.close();
         final Logger logger = 
LogManager.getLogger("org.apache.logging.log4j.test2.Test");
         logger.debug("This is a test");
-        final BufferedReader is = new BufferedReader(new InputStreamReader(new 
FileInputStream(LOGFILE)));
+        final BufferedReader is = new BufferedReader(new InputStreamReader(new 
FileInputStream(logFile)));
         try {
             int count = 0;
             String str = "";

Added: 
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude-appenders.xml
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude-appenders.xml?rev=1512556&view=auto
==============================================================================
--- 
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude-appenders.xml 
(added)
+++ 
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude-appenders.xml 
Sat Aug 10 03:31:49 2013
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<appenders>
+  <Console name="STDOUT">
+    <PatternLayout pattern="%m%n" />
+  </Console>
+  <File name="File" fileName="${filename}" bufferedIO="false">
+    <PatternLayout>
+      <pattern>%d %p %C{1.} [%t] %m%n</pattern>
+    </PatternLayout>
+  </File>
+  <List name="List">
+    <filters>
+      <ThresholdFilter level="error" />
+    </filters>
+  </List>
+</appenders>

Propchange: 
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude-appenders.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude-appenders.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Added: 
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude-loggers.xml
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude-loggers.xml?rev=1512556&view=auto
==============================================================================
--- 
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude-loggers.xml 
(added)
+++ 
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude-loggers.xml 
Sat Aug 10 03:31:49 2013
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<loggers>
+  <logger name="org.apache.logging.log4j.test1" level="debug" 
additivity="false">
+    <ThreadContextMapFilter>
+      <KeyValuePair key="test" value="123" />
+    </ThreadContextMapFilter>
+    <appender-ref ref="STDOUT" />
+  </logger>
+
+  <logger name="org.apache.logging.log4j.test2" level="debug" 
additivity="false">
+    <appender-ref ref="File" />
+  </logger>
+
+  <root level="error">
+    <appender-ref ref="STDOUT" />
+  </root>
+</loggers>
+  
\ No newline at end of file

Propchange: 
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude-loggers.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude-loggers.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Added: logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude.xml
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude.xml?rev=1512556&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude.xml 
(added)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude.xml Sat 
Aug 10 03:31:49 2013
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<configuration xmlns:xi="http://www.w3.org/2001/XInclude";
+  status="warn" name="XMLConfigTest" packages="org.apache.logging.log4j.test">
+  <properties>
+    <property name="filename">target/test.log</property>
+  </properties>
+  <ThresholdFilter level="debug"/>
+  <xi:include href="target/test-classes/log4j-xinclude-appenders.xml" />
+  <xi:include href="target/test-classes/log4j-xinclude-loggers.xml" />
+</configuration>
\ No newline at end of file

Propchange: 
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-xinclude.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1512556&r1=1512555&r2=1512556&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sat Aug 10 03:31:49 2013
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-beta9" date="soon, very soon" description="Bug fixes 
and enhancements">
+      <action issue="LOG4J2-341" dev="ggregory" type="add">
+        Enable XInclude for XML configurations.
+      </action>
       <action issue="LOG4J2-320" dev="ggregory" type="fix">
         JPAAppender stops logging because META-INF/log4j-provider.properties 
is left open.
       </action>


Reply via email to