logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1613427 - in /logging/log4j/log4j2/trunk: log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/ log4j-core/src/test/java/org/apache/logging/log4j/core/config/ log4j-core/src/test/resources/ src/changes/
Date Fri, 25 Jul 2014 13:00:09 GMT
Author: ggregory
Date: Fri Jul 25 13:00:09 2014
New Revision: 1613427

URL: http://svn.apache.org/r1613427
Log:
[LOG4J2-742] XInclude not working with relative path.

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

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java?rev=1613427&r1=1613426&r2=1613427&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
Fri Jul 25 13:00:09 2014
@@ -131,6 +131,7 @@ public class XmlConfiguration extends Ab
                 configStream.close();
             }
             final InputSource source = new InputSource(new ByteArrayInputStream(buffer));
+            source.setSystemId(configSource.getLocation());
             final Document document = newDocumentBuilder().parse(source);
             rootElement = document.getDocumentElement();
             final Map<String, String> attrs = processAttributes(rootNode, rootElement);

Added: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/config/XIncludeTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/config/XIncludeTest.java?rev=1613427&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/config/XIncludeTest.java
(added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/config/XIncludeTest.java
Fri Jul 25 13:00:09 2014
@@ -0,0 +1,138 @@
+/*
+ * 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.
+ */
+
+package org.apache.logging.log4j.core.config;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.security.SecureRandom;
+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.Logger;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.filter.ThreadContextMapFilter;
+import org.apache.logging.log4j.junit.CleanFiles;
+import org.apache.logging.log4j.junit.InitialLoggerContext;
+import org.apache.logging.log4j.util.Strings;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TestRule;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import static org.hamcrest.CoreMatchers.*;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests XInclude.
+ */
+@RunWith(Parameterized.class)
+public class XIncludeTest {
+
+    private static final String LOGGER_NAME = "org.apache.logging.log4j.test1.Test";
+    private static final String FILE_LOGGER_NAME = "org.apache.logging.log4j.test2.Test";
+    private static final String APPENDER_NAME = "STDOUT";
+
+    private final String logFileName;
+
+    @Rule
+    public TestRule rules;
+
+    private final InitialLoggerContext init;
+
+    private LoggerContext ctx;
+
+    private final SecureRandom random = new SecureRandom();
+
+    public XIncludeTest(final String configFileName, final String logFileName) {
+        this.logFileName = logFileName;
+        this.init = new InitialLoggerContext(configFileName);
+        rules = RuleChain.outerRule(new CleanFiles(logFileName)).around(this.init);
+    }
+
+    @Parameters
+    public static Collection<Object[]> data() {
+        return Arrays.asList(
+                new Object[][]{
+                        {"classpath:log4j-xinclude.xml", "target/test-xinclude.log"},
+                }
+        );
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        this.ctx = this.init.getContext();
+    }
+
+    @Test
+    public void testConfiguredAppenders() throws Exception {
+        final Configuration configuration = this.ctx.getConfiguration();
+        final Map<String, Appender> appenders = configuration.getAppenders();
+        assertThat(appenders, is(notNullValue()));
+        assertThat(appenders.size(), is(equalTo(3)));
+    }
+
+    @Test
+    public void testLogger() throws Exception {
+        final Logger logger = this.ctx.getLogger(LOGGER_NAME);
+        assertThat(logger, is(instanceOf(org.apache.logging.log4j.core.Logger.class)));
+        final org.apache.logging.log4j.core.Logger l = (org.apache.logging.log4j.core.Logger)
logger;
+        assertThat(l.getLevel(), is(equalTo(Level.DEBUG)));
+        assertThat(l.filterCount(), is(equalTo(1)));
+        final Iterator<Filter> iterator = l.getFilters();
+        assertThat(iterator.hasNext(), is(true));
+        final Filter filter = iterator.next();
+        assertThat(filter, is(instanceOf(ThreadContextMapFilter.class)));
+        final Map<String, Appender> appenders = l.getAppenders();
+        assertThat(appenders, is(notNullValue()));
+        assertThat(appenders.size(), is(equalTo(1)));
+        final Appender appender = appenders.get(APPENDER_NAME);
+        assertThat(appender, is(notNullValue()));
+        assertThat(appender.getName(), is(equalTo("STDOUT")));
+    }
+
+    @Test
+    public void testLogToFile() throws Exception {
+        final Logger logger = this.ctx.getLogger(FILE_LOGGER_NAME);
+        final long random = this.random.nextLong();
+        logger.debug("This is test message number {}", random);
+        int count = 0;
+        String line = Strings.EMPTY;
+        final BufferedReader in = new BufferedReader(new FileReader(this.logFileName));
+        try {
+            while (in.ready()) {
+                ++count;
+                line = in.readLine();
+            }
+        } finally {
+            in.close();
+        }
+        assertThat(count, is(equalTo(1)));
+        assertThat(line, endsWith(Long.toString(random)));
+    }
+
+}

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/config/XIncludeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/config/XIncludeTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j-xinclude.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j-xinclude.xml?rev=1613427&r1=1613426&r2=1613427&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j-xinclude.xml (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j-xinclude.xml Fri Jul 25
13:00:09 2014
@@ -19,9 +19,9 @@
 <Configuration xmlns:xi="http://www.w3.org/2001/XInclude"
   status="OFF" name="XMLConfigTest">
   <Properties>
-    <Property name="filename">target/test.log</Property>
+    <Property name="filename">target/test-xinclude.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
+  <xi:include href="log4j-xinclude-appenders.xml" />
+  <xi:include href="log4j-xinclude-loggers.xml" />
+</Configuration>

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1613427&r1=1613426&r2=1613427&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Fri Jul 25 13:00:09 2014
@@ -22,6 +22,9 @@
   </properties>
   <body>
     <release version="?" date="2014-mm-dd" description="?">
+      <action issue="LOG4J2-742" dev="ggreory" type="fix" due-to="Pascal Chollet">
+        XInclude not working with relative path.
+      </action>
       <action issue="LOG4J2-740" dev="mattsicker" type="fix" due-to="Kosta Krauth">
         Fixed typo in webapp manual regarding sample web.xml file.
       </action>



Mime
View raw message