You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2016/04/19 18:15:12 UTC
logging-log4j2 git commit: LOGj2-1263 - The ConfigurationSource was
not saved for BuiltConfigurations so monitor interval had no effect
Repository: logging-log4j2
Updated Branches:
refs/heads/master 69ddae41d -> eda5d279c
LOGj2-1263 - The ConfigurationSource was not saved for BuiltConfigurations so monitor interval had no effect
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/eda5d279
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/eda5d279
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/eda5d279
Branch: refs/heads/master
Commit: eda5d279c459e47cb4895546cc6b98ebe6b3712e
Parents: 69ddae4
Author: Ralph Goers <rg...@nextiva.com>
Authored: Tue Apr 19 09:15:04 2016 -0700
Committer: Ralph Goers <rg...@nextiva.com>
Committed: Tue Apr 19 09:15:10 2016 -0700
----------------------------------------------------------------------
.../config/builder/impl/BuiltConfiguration.java | 6 +-
.../properties/PropertiesConfiguration.java | 2 +-
.../PropertiesConfigurationBuilder.java | 6 ++
.../PropertiesConfigurationFactory.java | 5 +-
.../logging/log4j/core/FileConfigTest.java | 69 --------------------
.../log4j/core/PropertiesFileConfigTest.java | 69 ++++++++++++++++++++
.../src/test/resources/log4j-test2.properties | 59 +++++++++++++++++
src/changes/changes.xml | 3 +
8 files changed, 144 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/eda5d279/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/BuiltConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/BuiltConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/BuiltConfiguration.java
index 4a9b7e3..f096f84 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/BuiltConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/BuiltConfiguration.java
@@ -44,7 +44,7 @@ import org.apache.logging.log4j.core.util.Patterns;
public class BuiltConfiguration extends AbstractConfiguration {
private static final String[] VERBOSE_CLASSES = new String[] { ResolverUtil.class.getName() };
private final StatusConfiguration statusConfig;
- protected Component root;
+ protected Component rootComponent;
private Component loggersComponent;
private Component appendersComponent;
private Component filtersComponent;
@@ -84,7 +84,7 @@ public class BuiltConfiguration extends AbstractConfiguration {
}
}
}
- root = rootComponent;
+ this.rootComponent = rootComponent;
}
@Override
@@ -108,7 +108,7 @@ public class BuiltConfiguration extends AbstractConfiguration {
children.add(convertToNode(rootNode, filtersComponent));
}
}
- root = null;
+ rootComponent = null;
}
public String getContentType() {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/eda5d279/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfiguration.java
index 8a8e9fa..aa9eb59 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfiguration.java
@@ -43,7 +43,7 @@ public class PropertiesConfiguration extends BuiltConfiguration implements Recon
}
final PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory();
final PropertiesConfiguration config = factory.getConfiguration(source);
- return config.root.getComponents().size() == 0 ? null : config;
+ return config == null || config.getState() != State.INITIALIZED ? null : config;
} catch (final IOException ex) {
LOGGER.error("Cannot locate file {}: {}", getConfigurationSource(), ex);
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/eda5d279/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
index 8114a20..5645ee2 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
@@ -22,6 +22,7 @@ import java.util.Properties;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.ConfigurationException;
+import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.AppenderRefComponentBuilder;
@@ -69,6 +70,11 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory
return this;
}
+ public PropertiesConfigurationBuilder setConfigurationSource(ConfigurationSource source) {
+ builder.setConfigurationSource(source);
+ return this;
+ }
+
@Override
public PropertiesConfiguration build() {
builder
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/eda5d279/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationFactory.java
index 5742d7b..63cb323 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationFactory.java
@@ -28,7 +28,7 @@ import org.apache.logging.log4j.core.config.plugins.Plugin;
/**
* Creates a PropertiesConfiguration from a properties file.
- *
+ *
* @since 2.4
*/
@Plugin(name = "PropertiesConfigurationFactory", category = ConfigurationFactory.CATEGORY)
@@ -49,6 +49,7 @@ public class PropertiesConfigurationFactory extends ConfigurationFactory {
} catch (IOException ioe) {
throw new ConfigurationException("Unable to load " + source.toString(), ioe);
}
- return new PropertiesConfigurationBuilder().setRootProperties(properties).build();
+ return new PropertiesConfigurationBuilder().setConfigurationSource(source)
+ .setRootProperties(properties).build();
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/eda5d279/log4j-core/src/test/java/org/apache/logging/log4j/core/FileConfigTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/FileConfigTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/FileConfigTest.java
deleted file mode 100644
index 4cb4e59..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/FileConfigTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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;
-
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-
-/**
- *
- */
-public class FileConfigTest {
-
- private static final String CONFIG = "target/test-classes/log4j-test2.xml";
-
- @ClassRule
- public static LoggerContextRule context = new LoggerContextRule(CONFIG);
-
- private final org.apache.logging.log4j.Logger logger = context.getLogger("LoggerTest");
-
- @Before
- public void before() {
- context.getListAppender("List").clear();
- }
-
- @Test
- public void testReconfiguration() throws Exception {
- final Configuration oldConfig = context.getConfiguration();
- final int MONITOR_INTERVAL_SECONDS = 5;
- final File file = new File(CONFIG);
- final long orig = file.lastModified();
- final long newTime = orig + 10000;
- assertTrue("setLastModified should have succeeded.", file.setLastModified(newTime));
- TimeUnit.SECONDS.sleep(MONITOR_INTERVAL_SECONDS + 1);
- for (int i = 0; i < 17; ++i) {
- logger.debug("Reconfigure");
- }
- int loopCount = 0;
- Configuration newConfig;
- do {
- Thread.sleep(100);
- newConfig = context.getConfiguration();
- } while (newConfig == oldConfig && loopCount < 5);
- assertNotSame("Reconfiguration failed", newConfig, oldConfig);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/eda5d279/log4j-core/src/test/java/org/apache/logging/log4j/core/PropertiesFileConfigTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/PropertiesFileConfigTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/PropertiesFileConfigTest.java
new file mode 100644
index 0000000..d943c5e
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/PropertiesFileConfigTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class PropertiesFileConfigTest {
+
+ private static final String CONFIG = "target/test-classes/log4j-test2.properties";
+
+ @ClassRule
+ public static LoggerContextRule context = new LoggerContextRule(CONFIG);
+
+ private final org.apache.logging.log4j.Logger logger = context.getLogger("LoggerTest");
+
+ @Before
+ public void before() {
+ context.getListAppender("List").clear();
+ }
+
+ @Test
+ public void testReconfiguration() throws Exception {
+ final Configuration oldConfig = context.getConfiguration();
+ final int MONITOR_INTERVAL_SECONDS = 5;
+ final File file = new File(CONFIG);
+ final long orig = file.lastModified();
+ final long newTime = orig + 10000;
+ assertTrue("setLastModified should have succeeded.", file.setLastModified(newTime));
+ TimeUnit.SECONDS.sleep(MONITOR_INTERVAL_SECONDS + 1);
+ for (int i = 0; i < 17; ++i) {
+ logger.debug("Reconfigure");
+ }
+ int loopCount = 0;
+ Configuration newConfig;
+ do {
+ Thread.sleep(100);
+ newConfig = context.getConfiguration();
+ } while (newConfig == oldConfig && loopCount < 5);
+ assertNotSame("Reconfiguration failed", newConfig, oldConfig);
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/eda5d279/log4j-core/src/test/resources/log4j-test2.properties
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-test2.properties b/log4j-core/src/test/resources/log4j-test2.properties
new file mode 100644
index 0000000..25bd5dd
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-test2.properties
@@ -0,0 +1,59 @@
+#
+# 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.
+#
+
+status = debug
+name = PropertiesConfigTest
+monitorInterval = 1
+
+property.filename = target/test-properties.log
+
+filter.threshold.type = ThresholdFilter
+filter.threshold.level = debug
+
+appender.console.name = STDOUT
+appender.console.type = Console
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %m%n
+
+appender.file.name = File
+appender.file.type = File
+appender.file.fileName = ${filename}
+appender.file.bufferedIO = false
+appender.file.layout.type = PatternLayout
+appender.file.layout.pattern = %d %p %C{1.} [%t] %m%n
+
+appender.list.name = List
+appender.list.type = List
+appender.list.filter.threshold.type = ThresholdFilter
+appender.list.filter.threshold.level = error
+
+logger.test1.name = org.apache.logging.log4j.test1
+logger.test1.level = debug
+logger.test1.additivity = false
+logger.test1.filter.mdc.type = ThreadContextMapFilter
+logger.test1.filter.mdc.pair.type = KeyValuePair
+logger.test1.filter.mdc.pair.key = test
+logger.test1.filter.mdc.pair.value = 123
+logger.test1.appenderRef.console.ref = STDOUT
+
+logger.test2.name = org.apache.logging.log4j.test2
+logger.test2.level = debug
+logger.test2.additivity = false
+logger.test2.appenderRef.file.ref = File
+
+rootLogger.level = error
+rootLogger.appenderRef.console.ref = STDOUT
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/eda5d279/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 671d3c5..3239155 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -1265,6 +1265,9 @@
</action>
</release>
<release version="2.0-rc2" date="2014-06-21" description="Bug fixes and enhancements">
+ <action issue="LOG4J2-1263" dev="rgoers" type="fix">
+ The ConfigurationSource was not saved for BuiltConfigurations so monitor interval had no effect.
+ </action>
<action issue="LOG4J2-675" dev="rpopma" type="add">
RollingFile and RollingRandomAccessFile now write the layout footer before rollover.
</action>