[GIT] Logback: the generic, reliable, fast and flexible logging framework. branch master updated. v_1.0.0-48-g14125a6

This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Logback: the generic, reliable, fast and flexible logging framework.". The branch, master has been updated via 14125a6b372f8191fb8ab03e1f3838aab642f2ae (commit) from 458cf00deffe60253799f5c6f6d1ff5954309c80 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=14125a6b372f8191fb8ab03e1... http://github.com/ceki/logback/commit/14125a6b372f8191fb8ab03e1f3838aab642f2... commit 14125a6b372f8191fb8ab03e1f3838aab642f2ae Author: Ceki Gulcu <ceki@qos.ch> Date: Tue Nov 8 20:15:24 2011 +0100 test LBCORE-226 diff --git a/logback-core/src/main/java/ch/qos/logback/core/ContextBase.java b/logback-core/src/main/java/ch/qos/logback/core/ContextBase.java index 0f61df4..cd58377 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/ContextBase.java +++ b/logback-core/src/main/java/ch/qos/logback/core/ContextBase.java @@ -134,4 +134,9 @@ public class ContextBase implements Context { public ExecutorService getExecutorService() { return executorService; } + + @Override + public String toString() { + return name; + } } diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java index 0981f1f..0908a2f 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java +++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java @@ -93,6 +93,7 @@ public class TimeBasedRollingPolicy<E> extends RollingPolicyBase implements archiveRemover = timeBasedFileNamingAndTriggeringPolicy.getArchiveRemover(); archiveRemover.setMaxHistory(maxHistory); if(cleanHistoryOnStart) { + addInfo("Cleaning on start up"); archiveRemover.clean(new Date(timeBasedFileNamingAndTriggeringPolicy.getCurrentTime())); } } diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java index 352f5ac..85b494a 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java +++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DefaultArchiveRemover.java @@ -46,6 +46,7 @@ abstract public class DefaultArchiveRemover extends ContextAwareBase implements int computeElapsedPeriodsSinceLastClean(long nowInMillis) { long periodsElapsed = 0; if (lastHeartBeat == UNINITIALIZED) { + addInfo("first clean up after appender initialization"); periodsElapsed = rc.periodsElapsed(nowInMillis, nowInMillis + INACTIVITY_TOLERANCE_IN_MILLIS); if (periodsElapsed > MAX_VALUE_FOR_INACTIVITY_PERIODS) periodsElapsed = MAX_VALUE_FOR_INACTIVITY_PERIODS; @@ -67,7 +68,6 @@ abstract public class DefaultArchiveRemover extends ContextAwareBase implements addInfo("periodsElapsed = " + periodsElapsed); } for (int i = 0; i < periodsElapsed; i++) { - if (periodsElapsed > 1) addInfo("i = " + i); cleanByPeriodOffset(now, periodOffsetForDeletionTarget - i); } } diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedArchiveRemover.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedArchiveRemover.java index 2c65c41..0a2a90b 100644 --- a/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedArchiveRemover.java +++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedArchiveRemover.java @@ -35,4 +35,8 @@ public class TimeBasedArchiveRemover extends DefaultArchiveRemover { } } } + + public String toString() { + return "c.q.l.core.rolling.helper.TimeBasedArchiveRemover"; + } } diff --git a/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_STest.scala b/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_STest.scala index f392cdf..8a5d8ab 100644 --- a/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_STest.scala +++ b/logback-core/src/test/scala/ch/qos/logback/core/rolling/TimeBasedRollingWithArchiveRemoval_STest.scala @@ -61,7 +61,7 @@ class TimeBasedRollingWithArchiveRemoval_STest { val numPeriods: Int = 40 val maxHistory: Int = 2 val fileNamePattern = randomOutputDir + "/%d{" + MONTHLY_CRONOLOG_DATE_PATTERN + "}/clean.txt.zip" - val (startTime, endTime) = doRollover(now, fileNamePattern, MILLIS_IN_MONTH, maxHistory, numPeriods) + val (startTime, endTime) = logOverMultiplePeriods(now, fileNamePattern, MILLIS_IN_MONTH, maxHistory, numPeriods) val differenceInMonths = RollingCalendar.diffInMonths(startTime, endTime) val startTimeAsCalendar = Calendar.getInstance() startTimeAsCalendar.setTimeInMillis(startTime) @@ -81,7 +81,7 @@ class TimeBasedRollingWithArchiveRemoval_STest { def generateDailyRollover(now: Long, maxHistory: Int, simulatedNumberOfPeriods: Int, startInactivity: Int, numInactivityPeriods: Int) { slashCount = computeSlashCount(DAILY_DATE_PATTERN) - doRollover(now, randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt", MILLIS_IN_DAY, maxHistory, simulatedNumberOfPeriods, startInactivity, numInactivityPeriods) + logOverMultiplePeriods(now, randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt", MILLIS_IN_DAY, maxHistory, simulatedNumberOfPeriods, startInactivity, numInactivityPeriods) //StatusPrinter.print(context) check(expectedCountWithoutFoldersWithInactivity(maxHistory, simulatedNumberOfPeriods, startInactivity + numInactivityPeriods)) } @@ -110,15 +110,15 @@ class TimeBasedRollingWithArchiveRemoval_STest { slashCount = computeSlashCount(DAILY_DATE_PATTERN) val maxHistory = 5 val simulatedNumberOfPeriods = maxHistory * 2 - val (startTime, endTime) = doRollover(now, randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt", MILLIS_IN_DAY, maxHistory, maxHistory * 2) - doRollover(endTime + MILLIS_IN_DAY * 10, randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt", MILLIS_IN_DAY, maxHistory, maxHistory) + val (startTime, endTime) = logOverMultiplePeriods(now, randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt", MILLIS_IN_DAY, maxHistory, maxHistory * 2) + logOverMultiplePeriods(endTime + MILLIS_IN_DAY * 10, randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt", MILLIS_IN_DAY, maxHistory, maxHistory) check(expectedCountWithoutFolders(maxHistory)) } @Test def dailyCronologRollover { slashCount = computeSlashCount(DAILY_CRONOLOG_DATE_PATTERN) - doRollover(now, randomOutputDir + "/%d{" + DAILY_CRONOLOG_DATE_PATTERN + "}/clean.txt.zip", MILLIS_IN_DAY, 8, 8 * 3) + logOverMultiplePeriods(now, randomOutputDir + "/%d{" + DAILY_CRONOLOG_DATE_PATTERN + "}/clean.txt.zip", MILLIS_IN_DAY, 8, 8 * 3) var expectedDirMin: Int = 9 + slashCount var expectDirMax: Int = expectedDirMin + 1 + 1 expectedFileAndDirCount(9, expectedDirMin, expectDirMax) @@ -129,7 +129,7 @@ class TimeBasedRollingWithArchiveRemoval_STest { sizeAndTimeBasedFNATP.setMaxFileSize("10000") tbfnatp = sizeAndTimeBasedFNATP slashCount = computeSlashCount(DAILY_DATE_PATTERN) - doRollover(now, randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}-clean.%i.zip", MILLIS_IN_DAY, 5, 5 * 4) + logOverMultiplePeriods(now, randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}-clean.%i.zip", MILLIS_IN_DAY, 5, 5 * 4) checkPatternCompliance(5 + 1 + slashCount, "\\d{4}-\\d{2}-\\d{2}-clean(\\.\\d)(.zip)?") } @@ -138,7 +138,7 @@ class TimeBasedRollingWithArchiveRemoval_STest { sizeAndTimeBasedFNATP.setMaxFileSize("10000") tbfnatp = sizeAndTimeBasedFNATP slashCount = 1 - doRollover(now, randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}/clean.%i.zip", MILLIS_IN_DAY, 5, 5 * 4) + logOverMultiplePeriods(now, randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}/clean.%i.zip", MILLIS_IN_DAY, 5, 5 * 4) checkDirPatternCompliance(6) } @@ -149,21 +149,28 @@ class TimeBasedRollingWithArchiveRemoval_STest { slashCount = 1 val maxHistory = 5 val simulatedNumberOfPeriods = maxHistory * 4 - val (startTime, endTime) = doRollover(now, randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}/clean.%i", MILLIS_IN_DAY, maxHistory, 3) - doRollover(endTime + MILLIS_IN_DAY * 7, randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}/clean.%i", MILLIS_IN_DAY, maxHistory, simulatedNumberOfPeriods) + val (startTime, endTime) = logOverMultiplePeriods(now, randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}/clean.%i", MILLIS_IN_DAY, maxHistory, 3) + logOverMultiplePeriods(endTime + MILLIS_IN_DAY * 7, randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + "}/clean.%i", MILLIS_IN_DAY, maxHistory, simulatedNumberOfPeriods) checkDirPatternCompliance(maxHistory + 1) } - // this test requires changing the current working directory which is impossible in Java - @Ignore - @Test def dailyChronologSizeBasedRolloverWhenLogFilenameDoesNotContainDirectory: Unit = { - var sizeAndTimeBasedFNATP: SizeAndTimeBasedFNATP[AnyRef] = new SizeAndTimeBasedFNATP[AnyRef] - sizeAndTimeBasedFNATP.setMaxFileSize("10000") - tbfnatp = sizeAndTimeBasedFNATP - slashCount = 1 - doRollover(now, "clean.%d{" + DAILY_DATE_PATTERN + "}.%i.zip", MILLIS_IN_DAY, 5, 5 * 4) - checkDirPatternCompliance(6) + def logOncePeriod(currentTime: Long, fileNamePattern: String, maxHistory: Int) = { + val (rfa, tbrp) = buildRollingFileAppender(currentTime, fileNamePattern, maxHistory, true) + rfa.doAppend("Hello ----------------------------------------------------------" + new Date(currentTime)) + rfa.stop() + } + + @Test def cleanHistoryOnStart { + var now = this.now + val fileNamePattern = randomOutputDir + "clean-%d{" + DAILY_DATE_PATTERN + "}.txt" + val maxHistory = 3 + for (i <- 0 to 5) { + logOncePeriod(now, fileNamePattern, maxHistory) + now = now + MILLIS_IN_DAY + } + StatusPrinter.print(context) + check(expectedCountWithoutFolders(maxHistory)) } def extraFolder(numPeriods: Int, periodsPerEra: Int, beginPeriod: Int, maxHistory: Int): Boolean = { @@ -183,10 +190,8 @@ class TimeBasedRollingWithArchiveRemoval_STest { } } - def doRollover(currentTime: Long, fileNamePattern: String, periodDurationInMillis: Long, maxHistory: Int, - simulatedNumberOfPeriods: Int, startInactivity: Int = 0, - numInactivityPeriods: Int = 0): (Long, Long) = { - val startTime = currentTime + def buildRollingFileAppender(currentTime: Long, fileNamePattern: String, maxHistory: Int, + cleanHistoryOnStart: Boolean = false): (RollingFileAppender[AnyRef], TimeBasedRollingPolicy[AnyRef]) = { val rfa: RollingFileAppender[AnyRef] = new RollingFileAppender[AnyRef] rfa.setContext(context) rfa.setEncoder(encoder) @@ -195,11 +200,20 @@ class TimeBasedRollingWithArchiveRemoval_STest { tbrp.setFileNamePattern(fileNamePattern) tbrp.setMaxHistory(maxHistory) tbrp.setParent(rfa) + tbrp.setCleanHistoryOnStart(cleanHistoryOnStart) tbrp.timeBasedFileNamingAndTriggeringPolicy = tbfnatp tbrp.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime) tbrp.start rfa.setRollingPolicy(tbrp) rfa.start + (rfa, tbrp) + } + + def logOverMultiplePeriods(currentTime: Long, fileNamePattern: String, periodDurationInMillis: Long, maxHistory: Int, + simulatedNumberOfPeriods: Int, startInactivity: Int = 0, + numInactivityPeriods: Int = 0): (Long, Long) = { + val startTime = currentTime + val (rfa, tbrp) = buildRollingFileAppender(currentTime, fileNamePattern, maxHistory) val ticksPerPeriod: Int = 512 val runLength = simulatedNumberOfPeriods * ticksPerPeriod val startInactivityIndex: Int = 1 + startInactivity * ticksPerPeriod diff --git a/logback-site/src/site/pages/manual/appenders.html b/logback-site/src/site/pages/manual/appenders.html index 0d997d7..130aebc 100644 --- a/logback-site/src/site/pages/manual/appenders.html +++ b/logback-site/src/site/pages/manual/appenders.html @@ -818,6 +818,24 @@ public interface RollingPolicy extends LifeCycle { archiving will be removed as appropriate. </td> </tr> + + <tr class="b"> + <td><span class="option"><b>cleanHistoryOnStart</b></span></td> + <td>boolean</td> + <td> + <p>If set to true, archive removal will be executed on + appender start up. By default this property is set to + false. </p> + + <p>Archive removal is normally performed during roll + over. However, some applications may not live long enough for + roll over to be triggered. It follows that for such + short-lived applications archive removal may never get a + chance to execute. By setting <span + class="option">cleanHistoryOnStart</span> to true, archive + removal is performed at appender start up.</p> + </td> + </tr> </table> diff --git a/logback-site/src/site/pages/news.html b/logback-site/src/site/pages/news.html index 91ec85f..030ada1 100644 --- a/logback-site/src/site/pages/news.html +++ b/logback-site/src/site/pages/news.html @@ -31,6 +31,17 @@ <h3>xx of November, 2011 - Release of version 1.0.1</h3> + <p>Added new property the <span + class="option">cleanHistoryOnStart</span> to <a + href="manual/appenders.html#TimeBasedRollingPolicy">TimeBasedRollingPolicy</a>. + By setting this property to <code>true</code>, history removal + will work as expected even in the case of short lived + applications. This fixes <a + href="http://jira.qos.ch/browse/LBCORE-226">LBCORE-226</a> + reported by Bruce E. Irving. + </p> + + <p><code>RequestLogImpl</code> can now lookup for the logback-access configuration file as a class path resource. This feature was requested in <a ----------------------------------------------------------------------- Summary of changes: .../main/java/ch/qos/logback/core/ContextBase.java | 5 ++ .../core/rolling/TimeBasedRollingPolicy.java | 1 + .../core/rolling/helper/DefaultArchiveRemover.java | 2 +- .../rolling/helper/TimeBasedArchiveRemover.java | 4 ++ .../TimeBasedRollingWithArchiveRemoval_STest.scala | 58 ++++++++++++-------- logback-site/src/site/pages/manual/appenders.html | 18 ++++++ logback-site/src/site/pages/news.html | 11 ++++ 7 files changed, 76 insertions(+), 23 deletions(-) hooks/post-receive -- Logback: the generic, reliable, fast and flexible logging framework.
participants (1)
-
git-noreply@pixie.qos.ch