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:04:41 UTC
[logging-log4j2] branch release-2.x 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 release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new 7f840ca LOG4J2-2009 - Expose LoggerContext.setConfiguration as a public method.
7f840ca is described below
commit 7f840ca8feea0ba1cf00ed9a2ce11d05c52f94df
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Sat Feb 2 14:04:26 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 7a552cc..ddb5289 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
@@ -525,7 +525,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 ee56be5..f268aaf 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -31,6 +31,9 @@
- "remove" - Removed
-->
<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>