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 2019/02/02 21:05:12 UTC
[logging-log4j2] branch master updated: LOG4J2-2009 - Expose
LoggerContext.setConfiguration as a public method.
This is an automated email from the ASF dual-hosted git repository.
rgoers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/master by this push:
new 58fb311 LOG4J2-2009 - Expose LoggerContext.setConfiguration as a public method.
58fb311 is described below
commit 58fb311dad59c67c9a87353dc4ab32c12f1bb2c6
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Sat Feb 2 14:04:58 2019 -0700
LOG4J2-2009 - Expose LoggerContext.setConfiguration as a public method.
---
.../apache/logging/log4j/core/LoggerContext.java | 2 +-
.../rolling/RollingFileAppenderUpdateDataTest.java | 32 ++++++++++++++++++++--
src/changes/changes.xml | 3 ++
3 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
index 38dbef7..9d12421 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
@@ -521,7 +521,7 @@ public class LoggerContext extends AbstractLifeCycle
* @param config The new Configuration.
* @return The previous Configuration.
*/
- private Configuration setConfiguration(final Configuration config) {
+ public Configuration setConfiguration(final Configuration config) {
if (config == null) {
LOGGER.error("No configuration found for context '{}'.", contextName);
// No change, return the current configuration.
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderUpdateDataTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderUpdateDataTest.java
index 397679e..16900ca 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderUpdateDataTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderUpdateDataTest.java
@@ -26,7 +26,9 @@ import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
+import org.junit.After;
import org.junit.Assert;
+import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -63,6 +65,21 @@ public class RollingFileAppenderUpdateDataTest {
return builder;
}
+ private LoggerContext loggerContext1 = null;
+ private LoggerContext loggerContext2 = null;
+
+ @After
+ public void after() {
+ if (loggerContext1 != null) {
+ loggerContext1.close();
+ loggerContext1 = null;
+ }
+ if (loggerContext2 != null) {
+ loggerContext2.close();
+ loggerContext2 = null;
+ }
+ }
+
@Test
public void testClosingLoggerContext() {
// initial config with indexed rollover
@@ -79,16 +96,27 @@ public class RollingFileAppenderUpdateDataTest {
@Test
public void testNotClosingLoggerContext() {
// initial config with indexed rollover
- final LoggerContext loggerContext1 = Configurator.initialize(buildConfigA().build());
+ loggerContext1 = Configurator.initialize(buildConfigA().build());
validateAppender(loggerContext1, "target/rolling-update-date/foo.log.%i");
// rebuild config with date based rollover
- final LoggerContext loggerContext2 = Configurator.initialize(buildConfigB().build());
+ loggerContext2 = Configurator.initialize(buildConfigB().build());
Assert.assertNotNull("No LoggerContext", loggerContext2);
Assert.assertTrue("Expected same logger context to be returned", loggerContext1 == loggerContext2);
validateAppender(loggerContext1, "target/rolling-update-date/foo.log.%i");
}
+ @Test
+ public void testReconfigure() {
+ // initial config with indexed rollover
+ loggerContext1 = Configurator.initialize(buildConfigA().build());
+ validateAppender(loggerContext1, "target/rolling-update-date/foo.log.%i");
+
+ // rebuild config with date based rollover
+ loggerContext1.setConfiguration(buildConfigB().build());
+ validateAppender(loggerContext1, "target/rolling-update-date/foo.log.%d{yyyy-MM-dd-HH:mm:ss}.%i");
+ }
+
private void validateAppender(final LoggerContext loggerContext, final String expectedFilePattern) {
final RollingFileAppender appender = loggerContext.getConfiguration().getAppender("fooAppender");
Assert.assertNotNull(appender);
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 820a015..ca2862c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -354,6 +354,9 @@
</action>
</release>
<release version="2.11.2" date="2018-MM-DD" description="GA Release 2.11.2">
+ <action issue="LOG4J2-2009" dev="rgoers" type="fix">
+ Expose LoggerContext.setConfiguration as a public method.
+ </action>
<action issue="LOG4J2-2542" dev="rgoers" type="fix">
CronTriggeringPolicy was not rolling properly, especially when used with the SizeBasedTriggeringPolicy.
</action>