You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2022/01/20 23:27:39 UTC
[logging-log4j2] 01/02: Log4j 1.2 bridge throws ClassCastException when using SimpleLayout and others #708.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 3e7c4e667c3bec6d3c10f8c9d872fcacd4dac810
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Jan 20 18:27:28 2022 -0500
Log4j 1.2 bridge throws ClassCastException when using SimpleLayout and
others #708.
This is PR #708 from Piotr P. Karwasz with these changes:
- Add the Apache license header to XML test fixtures.
- Remove unused imports.
- Add missing spaces in Java source.
- Remove some whitespace.
---
.../appender/DailyRollingFileAppenderBuilder.java | 8 +-
.../appender/RollingFileAppenderBuilder.java | 8 +-
.../log4j/config/Log4j1ConfigurationParser.java | 10 +-
.../config/AbstractLog4j1ConfigurationTest.java | 116 +++++++++++++++++++++
.../config/Log4j1ConfigurationFactoryTest.java | 105 +++----------------
.../log4j/config/PropertiesConfigurationTest.java | 29 ++++++
.../apache/log4j/config/XmlConfigurationTest.java | 18 ++++
.../config-1.2/log4j-DailyRollingFileAppender.xml | 32 ++++++
.../config-1.2/log4j-RollingFileAppender.xml | 33 ++++++
.../config-1.2/log4j-system-properties-1.xml | 28 +++++
pom.xml | 3 +-
11 files changed, 278 insertions(+), 112 deletions(-)
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/DailyRollingFileAppenderBuilder.java b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/DailyRollingFileAppenderBuilder.java
index 5d0e69a..e68c5a1 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/DailyRollingFileAppenderBuilder.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/DailyRollingFileAppenderBuilder.java
@@ -40,6 +40,7 @@ import org.apache.log4j.spi.Filter;
import org.apache.log4j.xml.XmlConfiguration;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.appender.RollingFileAppender;
+import org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy;
import org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy;
import org.apache.logging.log4j.core.appender.rolling.RolloverStrategy;
import org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy;
@@ -48,7 +49,6 @@ import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.status.StatusLogger;
import org.w3c.dom.Element;
-
/**
* Build a Daily Rolling File Appender
*/
@@ -64,7 +64,6 @@ public class DailyRollingFileAppenderBuilder extends AbstractBuilder implements
super(prefix, props);
}
-
@Override
public Appender parseAppender(final Element appenderElement, final XmlConfiguration config) {
String name = getNameAttribute(appenderElement);
@@ -167,8 +166,9 @@ public class DailyRollingFileAppenderBuilder extends AbstractBuilder implements
LOGGER.warn("Unable to create File Appender, no file name provided");
return null;
}
- String filePattern = fileName +"%d{yyy-MM-dd}";
- TriggeringPolicy policy = TimeBasedTriggeringPolicy.newBuilder().withModulate(true).build();
+ String filePattern = fileName + "%d{.yyyy-MM-dd}";
+ TriggeringPolicy timePolicy = TimeBasedTriggeringPolicy.newBuilder().withModulate(true).build();
+ TriggeringPolicy policy = CompositeTriggeringPolicy.createPolicy(timePolicy);
RolloverStrategy strategy = DefaultRolloverStrategy.newBuilder()
.withConfig(configuration)
.withMax(Integer.toString(Integer.MAX_VALUE))
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/RollingFileAppenderBuilder.java b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/RollingFileAppenderBuilder.java
index b37afd9..f1dd914 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/RollingFileAppenderBuilder.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/RollingFileAppenderBuilder.java
@@ -44,13 +44,10 @@ import org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy;
import org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy;
import org.apache.logging.log4j.core.appender.rolling.RolloverStrategy;
import org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy;
-import org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy;
-import org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.status.StatusLogger;
import org.w3c.dom.Element;
-
/**
* Build a File Appender
*/
@@ -187,10 +184,9 @@ public class RollingFileAppenderBuilder extends AbstractBuilder implements Appen
LOGGER.warn("Unable to create File Appender, no file name provided");
return null;
}
- String filePattern = fileName +"%d{yyy-MM-dd}";
- TriggeringPolicy timePolicy = TimeBasedTriggeringPolicy.newBuilder().withModulate(true).build();
+ String filePattern = fileName + ".%i";
SizeBasedTriggeringPolicy sizePolicy = SizeBasedTriggeringPolicy.createPolicy(maxSize);
- CompositeTriggeringPolicy policy = CompositeTriggeringPolicy.createPolicy(sizePolicy, timePolicy);
+ CompositeTriggeringPolicy policy = CompositeTriggeringPolicy.createPolicy(sizePolicy);
RolloverStrategy strategy = DefaultRolloverStrategy.newBuilder()
.withConfig(config)
.withMax(maxBackups)
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
index 63f79ff..2007bbd 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
@@ -25,6 +25,7 @@ import java.util.Objects;
import java.util.Properties;
import java.util.TreeMap;
+import org.apache.log4j.helpers.OptionConverter;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.appender.FileAppender;
@@ -39,8 +40,6 @@ import org.apache.logging.log4j.core.config.builder.api.LayoutComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.LoggerComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
-import org.apache.logging.log4j.core.lookup.ConfigurationStrSubstitutor;
-import org.apache.logging.log4j.core.lookup.StrSubstitutor;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.util.Strings;
@@ -69,8 +68,6 @@ public class Log4j1ConfigurationParser {
private static final String FALSE = "false";
private final Properties properties = new Properties();
- private StrSubstitutor strSubstitutorProperties;
- private StrSubstitutor strSubstitutorSystem;
private final ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory
.newConfigurationBuilder();
@@ -90,8 +87,6 @@ public class Log4j1ConfigurationParser {
throws IOException {
try {
properties.load(input);
- strSubstitutorProperties = new ConfigurationStrSubstitutor(properties);
- strSubstitutorSystem = new ConfigurationStrSubstitutor(System.getProperties());
final String rootCategoryValue = getLog4jValue(ROOTCATEGORY);
final String rootLoggerValue = getLog4jValue(ROOTLOGGER);
if (rootCategoryValue == null && rootLoggerValue == null) {
@@ -422,8 +417,7 @@ public class Log4j1ConfigurationParser {
private String getProperty(final String key) {
final String value = properties.getProperty(key);
- final String sysValue = strSubstitutorSystem.replace(value);
- return strSubstitutorProperties.replace(sysValue);
+ return OptionConverter.substVars(value, properties);
}
private String getProperty(final String key, final String defaultValue) {
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/AbstractLog4j1ConfigurationTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/AbstractLog4j1ConfigurationTest.java
index 83fc2df..8e27c74 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/AbstractLog4j1ConfigurationTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/AbstractLog4j1ConfigurationTest.java
@@ -18,15 +18,28 @@ package org.apache.log4j.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
+import java.nio.file.FileSystemException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.concurrent.TimeUnit;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.appender.ConsoleAppender.Target;
+import org.apache.logging.log4j.core.appender.RollingFileAppender;
+import org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy;
+import org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy;
+import org.apache.logging.log4j.core.appender.rolling.RolloverStrategy;
+import org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy;
+import org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy;
+import org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.layout.PatternLayout;
@@ -81,4 +94,107 @@ public abstract class AbstractLog4j1ConfigurationTest {
assertEquals("%r [%t] %p %notEmpty{%ndc }- %m%n", layout.getConversionPattern());
}
+ public void testRollingFileAppender() throws Exception {
+ testRollingFileAppender("config-1.2/log4j-RollingFileAppender", "RFA", "target/hadoop.log.%i");
+ }
+
+ public void testDailyRollingFileAppender() throws Exception {
+ testDailyRollingFileAppender("config-1.2/log4j-DailyRollingFileAppender", "DRFA", "target/hadoop.log%d{.yyyy-MM-dd}");
+ }
+
+ public void testRollingFileAppenderWithProperties() throws Exception {
+ testRollingFileAppender("config-1.2/log4j-RollingFileAppender-with-props", "RFA", "target/hadoop.log.%i");
+ }
+
+ public void testSystemProperties1() throws Exception {
+ final String tempFileName = System.getProperty("java.io.tmpdir") + "/hadoop.log";
+ final Path tempFilePath = new File(tempFileName).toPath();
+ Files.deleteIfExists(tempFilePath);
+ try {
+ final Configuration configuration = getConfiguration("config-1.2/log4j-system-properties-1");
+ final RollingFileAppender appender = configuration.getAppender("RFA");
+ appender.stop(10, TimeUnit.SECONDS);
+ // System.out.println("expected: " + tempFileName + " Actual: " +
+ // appender.getFileName());
+ assertEquals(tempFileName, appender.getFileName());
+ } finally {
+ try {
+ Files.deleteIfExists(tempFilePath);
+ } catch (final FileSystemException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void testSystemProperties2() throws Exception {
+ final Configuration configuration = getConfiguration("config-1.2/log4j-system-properties-2");
+ final RollingFileAppender appender = configuration.getAppender("RFA");
+ final String tmpDir = System.getProperty("java.io.tmpdir");
+ assertEquals(tmpDir + "/hadoop.log", appender.getFileName());
+ appender.stop(10, TimeUnit.SECONDS);
+ // Try to clean up
+ try {
+ Path path = new File(appender.getFileName()).toPath();
+ Files.deleteIfExists(path);
+ path = new File("${java.io.tmpdir}").toPath();
+ Files.deleteIfExists(path);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void testRollingFileAppender(final String configResource, final String name, final String filePattern) throws Exception {
+ final Configuration configuration = getConfiguration(configResource);
+ final Appender appender = configuration.getAppender(name);
+ assertNotNull(appender);
+ assertEquals(name, appender.getName());
+ assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
+ final RollingFileAppender rfa = (RollingFileAppender) appender;
+ assertEquals("target/hadoop.log", rfa.getFileName());
+ assertEquals(filePattern, rfa.getFilePattern());
+ final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
+ assertNotNull(triggeringPolicy);
+ assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
+ final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
+ final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
+ assertEquals(1, triggeringPolicies.length);
+ final TriggeringPolicy tp = triggeringPolicies[0];
+ assertTrue(tp.getClass().getName(), tp instanceof SizeBasedTriggeringPolicy);
+ final SizeBasedTriggeringPolicy sbtp = (SizeBasedTriggeringPolicy) tp;
+ assertEquals(256 * 1024 * 1024, sbtp.getMaxFileSize());
+ final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
+ assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
+ final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
+ assertEquals(20, drs.getMaxIndex());
+ configuration.start();
+ configuration.stop();
+ }
+
+ private void testDailyRollingFileAppender(final String configResource, final String name, final String filePattern) throws Exception {
+ final Configuration configuration = getConfiguration(configResource);
+ final Appender appender = configuration.getAppender(name);
+ assertNotNull(appender);
+ assertEquals(name, appender.getName());
+ assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
+ final RollingFileAppender rfa = (RollingFileAppender) appender;
+ assertEquals("target/hadoop.log", rfa.getFileName());
+ assertEquals(filePattern, rfa.getFilePattern());
+ final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
+ assertNotNull(triggeringPolicy);
+ assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
+ final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
+ final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
+ assertEquals(1, triggeringPolicies.length);
+ final TriggeringPolicy tp = triggeringPolicies[0];
+ assertTrue(tp.getClass().getName(), tp instanceof TimeBasedTriggeringPolicy);
+ final TimeBasedTriggeringPolicy tbtp = (TimeBasedTriggeringPolicy) tp;
+ assertEquals(1, tbtp.getInterval());
+ final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
+ assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
+ final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
+ assertEquals(Integer.MAX_VALUE, drs.getMaxIndex());
+ configuration.start();
+ configuration.stop();
+ }
+
}
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
index a066789..f40cf7e 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
@@ -20,13 +20,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.io.File;
+
import java.net.URISyntaxException;
import java.net.URL;
-import java.nio.file.FileSystemException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.concurrent.TimeUnit;
+
import org.apache.log4j.layout.Log4j1XmlLayout;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.Appender;
@@ -35,13 +32,6 @@ import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.appender.ConsoleAppender.Target;
import org.apache.logging.log4j.core.appender.FileAppender;
import org.apache.logging.log4j.core.appender.NullAppender;
-import org.apache.logging.log4j.core.appender.RollingFileAppender;
-import org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy;
-import org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy;
-import org.apache.logging.log4j.core.appender.rolling.RolloverStrategy;
-import org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy;
-import org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy;
-import org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.layout.HtmlLayout;
@@ -143,105 +133,33 @@ public class Log4j1ConfigurationFactoryTest extends AbstractLog4j1ConfigurationT
assertTrue(appender.getClass().getName(), appender instanceof NullAppender);
}
+ @Override
@Test
public void testRollingFileAppender() throws Exception {
- testRollingFileAppender("config-1.2/log4j-RollingFileAppender", "RFA", "target/hadoop.log.%i");
+ super.testRollingFileAppender();
}
+ @Override
@Test
public void testDailyRollingFileAppender() throws Exception {
- testDailyRollingFileAppender("config-1.2/log4j-DailyRollingFileAppender", "DRFA", "target/hadoop.log%d{.yyyy-MM-dd}");
+ super.testDailyRollingFileAppender();
}
@Test
public void testRollingFileAppenderWithProperties() throws Exception {
- testRollingFileAppender("config-1.2/log4j-RollingFileAppender-with-props", "RFA", "target/hadoop.log.%i");
+ super.testRollingFileAppenderWithProperties();
}
+ @Override
@Test
public void testSystemProperties1() throws Exception {
- final String tempFileName = System.getProperty("java.io.tmpdir") + "/hadoop.log";
- final Path tempFilePath = new File(tempFileName).toPath();
- Files.deleteIfExists(tempFilePath);
- try {
- final Configuration configuration = getConfiguration("config-1.2/log4j-system-properties-1");
- final RollingFileAppender appender = configuration.getAppender("RFA");
- appender.stop(10, TimeUnit.SECONDS);
- // System.out.println("expected: " + tempFileName + " Actual: " + appender.getFileName());
- assertEquals(tempFileName, appender.getFileName());
- } finally {
- try {
- Files.deleteIfExists(tempFilePath);
- } catch (final FileSystemException e) {
- e.printStackTrace();
- }
- }
+ super.testSystemProperties1();
}
+ @Override
@Test
public void testSystemProperties2() throws Exception {
- final Configuration configuration = getConfiguration("config-1.2/log4j-system-properties-2");
- final RollingFileAppender appender = configuration.getAppender("RFA");
- assertEquals("${java.io.tmpdir}/hadoop.log", appender.getFileName());
- appender.stop(10, TimeUnit.SECONDS);
- Path path = new File(appender.getFileName()).toPath();
- Files.deleteIfExists(path);
- path = new File("${java.io.tmpdir}").toPath();
- Files.deleteIfExists(path);
- }
-
- private void testRollingFileAppender(final String configResource, final String name, final String filePattern) throws URISyntaxException {
- final Configuration configuration = getConfiguration(configResource);
- final Appender appender = configuration.getAppender(name);
- assertNotNull(appender);
- assertEquals(name, appender.getName());
- assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
- final RollingFileAppender rfa = (RollingFileAppender) appender;
- assertEquals("target/hadoop.log", rfa.getFileName());
- assertEquals(filePattern, rfa.getFilePattern());
- final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
- assertNotNull(triggeringPolicy);
- assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
- final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
- final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
- assertEquals(1, triggeringPolicies.length);
- final TriggeringPolicy tp = triggeringPolicies[0];
- assertTrue(tp.getClass().getName(), tp instanceof SizeBasedTriggeringPolicy);
- final SizeBasedTriggeringPolicy sbtp = (SizeBasedTriggeringPolicy) tp;
- assertEquals(256 * 1024 * 1024, sbtp.getMaxFileSize());
- final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
- assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
- final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
- assertEquals(20, drs.getMaxIndex());
- configuration.start();
- configuration.stop();
- }
-
- private void testDailyRollingFileAppender(final String configResource, final String name, final String filePattern) throws URISyntaxException {
- final Configuration configuration = getConfiguration(configResource);
- final Appender appender = configuration.getAppender(name);
- assertNotNull(appender);
- assertEquals(name, appender.getName());
- assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
- final RollingFileAppender rfa = (RollingFileAppender) appender;
- assertEquals("target/hadoop.log", rfa.getFileName());
- assertEquals(filePattern, rfa.getFilePattern());
- final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
- assertNotNull(triggeringPolicy);
- assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
- final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
- final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
- assertEquals(1, triggeringPolicies.length);
- final TriggeringPolicy tp = triggeringPolicies[0];
- assertTrue(tp.getClass().getName(), tp instanceof TimeBasedTriggeringPolicy);
- final TimeBasedTriggeringPolicy tbtp = (TimeBasedTriggeringPolicy) tp;
- assertEquals(1, tbtp.getInterval());
- final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
- assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
- final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
- assertEquals(Integer.MAX_VALUE, drs.getMaxIndex());
- configuration.start();
- configuration.stop();
+ super.testSystemProperties2();
}
@Override
@@ -249,4 +167,5 @@ public class Log4j1ConfigurationFactoryTest extends AbstractLog4j1ConfigurationT
public void testConsoleCapitalization() throws Exception {
super.testConsoleCapitalization();
}
+
}
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java
index 7e8b7dd..17d6480 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java
@@ -196,4 +196,33 @@ public class PropertiesConfigurationTest extends AbstractLog4j1ConfigurationTest
super.testConsoleTtccLayout();
}
+ @Override
+ @Test
+ public void testRollingFileAppender() throws Exception {
+ super.testRollingFileAppender();
+ }
+
+ @Override
+ @Test
+ public void testDailyRollingFileAppender() throws Exception {
+ super.testDailyRollingFileAppender();
+ }
+
+ @Override
+ @Test
+ public void testRollingFileAppenderWithProperties() throws Exception {
+ super.testRollingFileAppenderWithProperties();
+ }
+
+ @Override
+ @Test
+ public void testSystemProperties1() throws Exception {
+ super.testSystemProperties1();
+ }
+
+ @Override
+ @Test
+ public void testSystemProperties2() throws Exception {
+ super.testSystemProperties2();
+ }
}
\ No newline at end of file
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/XmlConfigurationTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/XmlConfigurationTest.java
index 6e91938..35a6436 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/XmlConfigurationTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/XmlConfigurationTest.java
@@ -106,4 +106,22 @@ public class XmlConfigurationTest extends AbstractLog4j1ConfigurationTest {
super.testConsoleTtccLayout();
}
+ @Override
+ @Test
+ public void testRollingFileAppender() throws Exception {
+ super.testRollingFileAppender();
+ }
+
+ @Override
+ @Test
+ public void testDailyRollingFileAppender() throws Exception {
+ super.testDailyRollingFileAppender();
+ }
+
+ @Override
+ @Test
+ public void testSystemProperties1() throws Exception {
+ super.testSystemProperties1();
+ }
+
}
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-DailyRollingFileAppender.xml b/log4j-1.2-api/src/test/resources/config-1.2/log4j-DailyRollingFileAppender.xml
new file mode 100644
index 0000000..fbec94f
--- /dev/null
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-DailyRollingFileAppender.xml
@@ -0,0 +1,32 @@
+<?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.
+-->
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+ <appender name="DRFA" class="org.apache.log4j.DailyRollingFileAppender">
+ <param name="File" value="target/hadoop.log" />
+ <param name="DatePattern" value=".yyyy-MM-dd" />
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d{ISO8601} %p %c: %m%n" />
+ </layout>
+ </appender>
+
+ <root>
+ <priority value="trace" />
+ <appender-ref ref="DRFA" />
+ </root>
+</log4j:configuration>
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-RollingFileAppender.xml b/log4j-1.2-api/src/test/resources/config-1.2/log4j-RollingFileAppender.xml
new file mode 100644
index 0000000..5a20064
--- /dev/null
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-RollingFileAppender.xml
@@ -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.
+-->
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+ <appender name="RFA" class="org.apache.log4j.RollingFileAppender">
+ <param name="File" value="target/hadoop.log" />
+ <param name="MaxFileSize" value="256MB" />
+ <param name="MaxBackupIndex" value="20" />
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d{ISO8601} %p %c: %m%n" />
+ </layout>
+ </appender>
+
+ <root>
+ <priority value="trace" />
+ <appender-ref ref="RFA" />
+ </root>
+</log4j:configuration>
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-system-properties-1.xml b/log4j-1.2-api/src/test/resources/config-1.2/log4j-system-properties-1.xml
new file mode 100644
index 0000000..8ced3f5
--- /dev/null
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-system-properties-1.xml
@@ -0,0 +1,28 @@
+<?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.
+-->
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+ <appender name="RFA" class="org.apache.log4j.DailyRollingFileAppender">
+ <param name="File" value="${java.io.tmpdir}/hadoop.log" />
+ </appender>
+
+ <root>
+ <priority value="trace" />
+ <appender-ref ref="RFA" />
+ </root>
+</log4j:configuration>
diff --git a/pom.xml b/pom.xml
index 1e03f67..4eef768 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,8 @@
~ 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.
- --><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId>