Repository: logging-log4j2 Updated Branches: refs/heads/master 0d87f2039 -> d3c09fadd
LOG4J2-1649 - Insure the ConfigurationScheduler shuts down without blocking. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d3c09fad Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d3c09fad Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d3c09fad Branch: refs/heads/master Commit: d3c09fadd5208193e0dcb99a97dc6b433f91526c Parents: 0d87f20 Author: Ralph Goers <[email protected]> Authored: Sun Jan 1 23:38:16 2017 -0700 Committer: Ralph Goers <[email protected]> Committed: Sun Jan 1 23:38:16 2017 -0700 ---------------------------------------------------------------------- .../core/config/ConfigurationScheduler.java | 10 +++++++- .../logging/log4j/core/CronRolloverApp.java | 27 ++++++++++++++++++++ .../test/resources/log4j-cronRolloverApp.xml | 24 +++++++++++++++++ src/changes/changes.xml | 5 +++- 4 files changed, 64 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3c09fad/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java index f54fc49..60a28f6 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java @@ -17,6 +17,7 @@ package org.apache.logging.log4j.core.config; import java.util.Date; +import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; @@ -48,7 +49,14 @@ public class ConfigurationScheduler extends AbstractLifeCycle { setStopping(); if (isExecutorServiceSet()) { LOGGER.debug("{} shutting down threads in {}", SIMPLE_NAME, getExecutorService()); - getExecutorService().shutdown(); + List<Runnable> tasks = executorService.shutdownNow(); + if (tasks != null && tasks.size() > 0) { + try { + executorService.awaitTermination(timeout, timeUnit); + } catch (InterruptedException ie) { + LOGGER.warn("ConfigurationScheduler stopped before all tasks were completed."); + } + } } setStopped(); return true; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3c09fad/log4j-core/src/test/java/org/apache/logging/log4j/core/CronRolloverApp.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/CronRolloverApp.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/CronRolloverApp.java new file mode 100644 index 0000000..7ba7816 --- /dev/null +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/CronRolloverApp.java @@ -0,0 +1,27 @@ +package org.apache.logging.log4j.core; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * Created by rgoers on 1/1/17. + */ +public class CronRolloverApp { + + + private static Logger logger; + + public static void main(String[] args) { + System.setProperty("log4j.configurationFile", "target/test-classes/log4j-cronRolloverApp.xml"); + logger = LogManager.getLogger(CronRolloverApp.class); + try { + for (int i = 1; i <= 240; i++) { + logger.info("Hello"); + Thread.sleep(1 * 1000); + } + } catch (Exception e) { + //e.printStackTrace(); + logger.error("Excepcion general", e); + } + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3c09fad/log4j-core/src/test/resources/log4j-cronRolloverApp.xml ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/resources/log4j-cronRolloverApp.xml b/log4j-core/src/test/resources/log4j-cronRolloverApp.xml new file mode 100644 index 0000000..d80fded --- /dev/null +++ b/log4j-core/src/test/resources/log4j-cronRolloverApp.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration status="warn" name="testlog4j2" packages=""> + <Properties> + <Property name="baseDir">target/testlog4</Property> + </Properties> + <Appenders> + <RollingFile name="RollingFile" fileName="${baseDir}/app.log" + filePattern="${baseDir}/$${date:yyyy-MM}/app-%d{yyyy-MM-dd-HH-mm}.log.gz"> + <PatternLayout pattern="%d %p %c{1.} [%t] %m%n" /> + <CronTriggeringPolicy schedule="0 0/1 * * * ?"/> + <DefaultRolloverStrategy> + <Delete basePath="${baseDir}" maxDepth="2"> + <IfFileName glob="*/app-*.log.gz" /> + <IfLastModified age="60d" /> + </Delete> + </DefaultRolloverStrategy> + </RollingFile> + </Appenders> + <Loggers> + <Root level="ALL"> + <AppenderRef ref="RollingFile"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d3c09fad/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e38201b..4ae700d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -24,7 +24,10 @@ </properties> <body> <release version="2.8" date="2016-MM-DD" description="GA Release 2.8"> - <action issue="LOG4J2-1653" dev="rgoers" type="fix"> + <action issue="LOG4J2-1649" dev="rgoers" type="fix" due-to="Georg Friedrich"> + Insure the ConfigurationScheduler shuts down without blocking. + </action> + <action issue="LOG4J2-1653" dev="rgoers" type="fix" due-to=" Georg Friedrich"> CronTriggeringPolicy would use the wrong date/time when rolling over and create multiple triggering policies on reconfiguration. </action> <action issue="LOG4J2-1748" dev="rpopma" type="fix">
