logback-dev
Threads by month
- ----- 2025 -----
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
July 2009
- 10 participants
- 153 discussions

svn commit: r2382 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/pattern/parser main/java/ch/qos/logback/core/rolling main/java/ch/qos/logback/core/rolling/helper test/java/ch/qos/logback/core/rolling/helper
by noreply.ceki@qos.ch 30 Jul '09
by noreply.ceki@qos.ch 30 Jul '09
30 Jul '09
Author: ceki
Date: Thu Jul 30 18:57:14 2009
New Revision: 2382
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicy.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/MonoTypedConverter.java
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/TokenStream.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/IntegerTokenConverter.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
Log:
Further preparatory work on time and size based rolling - related to LBCORE-90
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/TokenStream.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/TokenStream.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/pattern/parser/TokenStream.java Thu Jul 30 18:57:14 2009
@@ -1,11 +1,11 @@
-/**
- * LOGBack: the reliable, fast and flexible logging library for Java.
- *
- * Copyright (C) 1999-2005, QOS.ch, LOGBack.com
- *
- * This library is free software, you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation.
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2009, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
*/
package ch.qos.logback.core.pattern.parser;
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java Thu Jul 30 18:57:14 2009
@@ -3,78 +3,17 @@
import java.io.File;
import java.util.Date;
-import ch.qos.logback.core.rolling.helper.DateTokenConverter;
-import ch.qos.logback.core.rolling.helper.RollingCalendar;
-import ch.qos.logback.core.spi.ContextAwareBase;
-
-public class DefaultTimeBasedFileNamingAndTriggeringPolicy<E> extends ContextAwareBase
- implements TimeBasedFileNamingAndTriggeringPolicy<E> {
-
- private TimeBasedRollingPolicy<E> tbrp;
- private String elapsedPeriodsFileName;
- private RollingCalendar rc;
- private long currentTime;
- private long nextCheck;
- // indicate whether the time has been forced or not
- private boolean isTimeForced = false;
- private Date dateInCurrentPeriod = null;
- boolean started = false;
+public class DefaultTimeBasedFileNamingAndTriggeringPolicy<E> extends TimeBasedFileNamingAndTriggeringPolicyBase<E> {
- public boolean isStarted() {
- return started;
- }
-
- public void start() {
-
- DateTokenConverter dtc = tbrp.fileNamePattern.getDateTokenConverter();
- if (dtc == null) {
- throw new IllegalStateException("FileNamePattern ["
- + tbrp.fileNamePattern.getPattern()
- + "] does not contain a valid DateToken");
- }
- rc = new RollingCalendar();
- rc.init(dtc.getDatePattern());
- addInfo("The date pattern is '" + dtc.getDatePattern()
- + "' from file name pattern '" + tbrp.fileNamePattern.getPattern()
- + "'.");
- rc.printPeriodicity(this);
-
- // dateInCurrentPeriod can be set by test classes
- // if it has not been set, we set it here
- if (dateInCurrentPeriod == null) {
- dateInCurrentPeriod = new Date();
- updateDateInCurrentPeriod(getCurrentTime());
- }
- computeNextCheck();
- }
-
- public void stop() {
- started = false;
+ @Override
+ public void start() {
+ super.start();
+
+ started = true;
}
- private void computeNextCheck() {
- nextCheck = rc.getNextTriggeringMillis(dateInCurrentPeriod);
- }
-
- // allow Test classes to act on the dateInCurrentPeriod field to simulate old
- // log files needing rollover
- public void setDateInCurrentPeriod(Date _dateInCurrentPeriod) {
- this.dateInCurrentPeriod = _dateInCurrentPeriod;
- }
-
- public Date getDateInCurrentPeriod() {
- return dateInCurrentPeriod;
- }
-
- public String getElapsedPeriodsFileName() {
- return elapsedPeriodsFileName;
- }
-
- public String getCurrentPeriodsFileNameWithoutCompressionSuffix() {
- return tbrp.fileNamePatternWCS.convertDate(dateInCurrentPeriod);
- }
public boolean isTriggeringEvent(File activeFile, final E event) {
long time = getCurrentTime();
@@ -90,32 +29,4 @@
return false;
}
}
-
- private void updateDateInCurrentPeriod(long now) {
- dateInCurrentPeriod.setTime(now);
- }
-
- public void setCurrentTime(long timeInMillis) {
- currentTime = timeInMillis;
- isTimeForced = true;
- }
-
- public long getCurrentTime() {
- // if time is forced return the time set by user
- if (isTimeForced) {
- return currentTime;
- } else {
- return System.currentTimeMillis();
- }
- }
-
- public void setTimeBasedRollingPolicy(TimeBasedRollingPolicy<E> _tbrp) {
- this.tbrp = _tbrp;
-
- }
-
- public RollingCalendar getRollingCalendar() {
- return rc;
- }
-
}
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicy.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/SizeAndTimeBasedFileNamingAndTriggeringPolicy.java Thu Jul 30 18:57:14 2009
@@ -0,0 +1,38 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2009, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.core.rolling;
+
+import java.io.File;
+import java.util.Date;
+
+public class SizeAndTimeBasedFileNamingAndTriggeringPolicy<E> extends TimeBasedFileNamingAndTriggeringPolicyBase<E> {
+
+
+ @Override
+ public void start() {
+ super.start();
+ started = true;
+ }
+
+ public boolean isTriggeringEvent(File activeFile, final E event) {
+ long time = getCurrentTime();
+
+ if (time >= nextCheck) {
+ Date dateInElapsedPeriod = dateInCurrentPeriod;
+ elapsedPeriodsFileName = tbrp.fileNamePatternWCS
+ .convertDate(dateInElapsedPeriod);
+ updateDateInCurrentPeriod(time);
+ computeNextCheck();
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicyBase.java Thu Jul 30 18:57:14 2009
@@ -0,0 +1,113 @@
+package ch.qos.logback.core.rolling;
+
+import java.util.Date;
+
+import ch.qos.logback.core.rolling.helper.DateTokenConverter;
+import ch.qos.logback.core.rolling.helper.RollingCalendar;
+import ch.qos.logback.core.spi.ContextAwareBase;
+
+abstract public class TimeBasedFileNamingAndTriggeringPolicyBase<E> extends ContextAwareBase
+ implements TimeBasedFileNamingAndTriggeringPolicy<E> {
+
+ protected TimeBasedRollingPolicy<E> tbrp;
+
+
+ protected String elapsedPeriodsFileName;
+ protected RollingCalendar rc;
+
+
+ protected long currentTime;
+ //indicate whether the time has been forced or not
+ protected boolean isTimeForced = false;
+ protected Date dateInCurrentPeriod = null;
+
+
+ protected long nextCheck;
+ protected boolean started = false;
+
+
+ public boolean isStarted() {
+ return started;
+ }
+
+ public void start() {
+
+ DateTokenConverter dtc = tbrp.fileNamePattern.getDateTokenConverter();
+
+ if (dtc == null) {
+ throw new IllegalStateException("FileNamePattern ["
+ + tbrp.fileNamePattern.getPattern()
+ + "] does not contain a valid DateToken");
+ }
+
+ rc = new RollingCalendar();
+ rc.init(dtc.getDatePattern());
+ addInfo("The date pattern is '" + dtc.getDatePattern()
+ + "' from file name pattern '" + tbrp.fileNamePattern.getPattern()
+ + "'.");
+ rc.printPeriodicity(this);
+
+ // dateInCurrentPeriod can be set by test classes
+ // if it has not been set, we set it here
+ if (dateInCurrentPeriod == null) {
+ dateInCurrentPeriod = new Date();
+ updateDateInCurrentPeriod(getCurrentTime());
+ }
+ computeNextCheck();
+ }
+
+ public void stop() {
+ started = false;
+ }
+
+ protected void computeNextCheck() {
+ nextCheck = rc.getNextTriggeringMillis(dateInCurrentPeriod);
+ }
+
+ // allow Test classes to act on the dateInCurrentPeriod field to simulate old
+ // log files needing rollover
+ public void setDateInCurrentPeriod(Date _dateInCurrentPeriod) {
+ this.dateInCurrentPeriod = _dateInCurrentPeriod;
+ }
+
+ public Date getDateInCurrentPeriod() {
+ return dateInCurrentPeriod;
+ }
+
+ public String getElapsedPeriodsFileName() {
+ return elapsedPeriodsFileName;
+ }
+
+ public String getCurrentPeriodsFileNameWithoutCompressionSuffix() {
+ return tbrp.fileNamePatternWCS.convertDate(dateInCurrentPeriod);
+ }
+
+
+ protected void updateDateInCurrentPeriod(long now) {
+ dateInCurrentPeriod.setTime(now);
+ }
+
+ public void setCurrentTime(long timeInMillis) {
+ currentTime = timeInMillis;
+ isTimeForced = true;
+ }
+
+ public long getCurrentTime() {
+ // if time is forced return the time set by user
+ if (isTimeForced) {
+ return currentTime;
+ } else {
+ return System.currentTimeMillis();
+ }
+ }
+
+ public void setTimeBasedRollingPolicy(TimeBasedRollingPolicy<E> _tbrp) {
+ this.tbrp = _tbrp;
+
+ }
+
+ public RollingCalendar getRollingCalendar() {
+ return rc;
+ }
+
+}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/DateTokenConverter.java Thu Jul 30 18:57:14 2009
@@ -15,13 +15,17 @@
import ch.qos.logback.core.pattern.DynamicConverter;
-
/**
- *
+ *
* @author Ceki Gücü
*/
-public class DateTokenConverter extends DynamicConverter {
-
+public class DateTokenConverter extends DynamicConverter implements MonoTypedConverter {
+
+ /**
+ * The conversion word/character with which this converter is registered.
+ */
+ public final static String CONVERTER_KEY = "d";
+
String datePattern;
SimpleDateFormat sdf;
@@ -30,25 +34,27 @@
public void start() {
this.datePattern = getFirstOption();
- if(this.datePattern == null) {
- this.datePattern = "yyyy-MM-dd";;
+ if (this.datePattern == null) {
+ this.datePattern = "yyyy-MM-dd";
+ ;
}
sdf = new SimpleDateFormat(datePattern);
}
-
+
public String convert(Date date) {
return sdf.format(date);
}
-
+
public String convert(Object o) {
- if(o == null) {
+ if (o == null) {
throw new IllegalArgumentException("Null argument forbidden");
}
- if(o instanceof Date) {
+ if (o instanceof Date) {
return convert((Date) o);
- }
+ }
throw new IllegalArgumentException("Cannot convert "+o+" of type"+o.getClass().getName());
}
+
/**
* Return the date pattern.
*/
@@ -56,11 +62,14 @@
return datePattern;
}
+ public boolean isApplicable(Object o) {
+ return (o instanceof Date);
+ }
+
/**
* Set the date pattern.
*/
- //public void setDatePattern(String string) {
- // datePattern = string;
- //}
-
+ // public void setDatePattern(String string) {
+ // datePattern = string;
+ // }
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java Thu Jul 30 18:57:14 2009
@@ -1,7 +1,7 @@
/**
- * LOGBack: the reliable, fast and flexible logging library for Java.
+ * Logback: the generic, reliable, fast and flexible logging framework.
*
- * Copyright (C) 1999-2006, QOS.ch
+ * Copyright (C) 2000-2009, QOS.ch
*
* This library is free software, you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
@@ -12,6 +12,7 @@
import java.util.Date;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import ch.qos.logback.core.Context;
@@ -23,12 +24,10 @@
import ch.qos.logback.core.pattern.util.AlmostAsIsEscapeUtil;
import ch.qos.logback.core.spi.ContextAwareBase;
-
/**
- *
- * After parsing file name patterns, given a number or a date, instances of this class
- * can be used to compute a file name according to the file name pattern and the given
- * integer or date.
+ * After parsing file name patterns, given a number or a date, instances of this
+ * class can be used to compute a file name according to the file name pattern
+ * and the given integer or date.
*
* @author Ceki Gülcü
*
@@ -37,8 +36,8 @@
static final Map<String, String> CONVERTER_MAP = new HashMap<String, String>();
static {
- CONVERTER_MAP.put("i", IntegerTokenConverter.class.getName());
- CONVERTER_MAP.put("d", DateTokenConverter.class.getName());
+ CONVERTER_MAP.put(IntegerTokenConverter.CONVERTER_KEY, IntegerTokenConverter.class.getName());
+ CONVERTER_MAP.put(DateTokenConverter.CONVERTER_KEY, DateTokenConverter.class.getName());
}
String pattern;
@@ -94,9 +93,29 @@
return null;
}
+
+ public String convertList(List<Object> objectList) {
+ StringBuilder buf = new StringBuilder();
+ Converter<Object> c = headTokenConverter;
+ while (c != null) {
+ if(c instanceof MonoTypedConverter) {
+ MonoTypedConverter monoTyped = (MonoTypedConverter) c;
+ for(Object o: objectList) {
+ if(monoTyped.isApplicable(o)) {
+ buf.append(c.convert(o));
+ }
+ }
+ } else {
+ buf.append(c.convert(objectList));
+ }
+ c = c.getNext();
+ }
+ return buf.toString();
+ }
+
public String convert(Object o) {
+ StringBuilder buf = new StringBuilder();
Converter<Object> p = headTokenConverter;
- StringBuffer buf = new StringBuffer();
while (p != null) {
buf.append(p.convert(o));
p = p.getNext();
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/IntegerTokenConverter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/IntegerTokenConverter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/IntegerTokenConverter.java Thu Jul 30 18:57:14 2009
@@ -1,7 +1,7 @@
/**
- * LOGBack: the reliable, fast and flexible logging library for Java.
+ * Logback: the generic, reliable, fast and flexible logging framework.
*
- * Copyright (C) 1999-2006, QOS.ch
+ * Copyright (C) 2000-2009, QOS.ch
*
* This library is free software, you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
@@ -17,8 +17,10 @@
*
* @author Ceki Gulcu
*/
-public class IntegerTokenConverter extends DynamicConverter {
+public class IntegerTokenConverter extends DynamicConverter implements MonoTypedConverter {
+ public final static String CONVERTER_KEY = "i";
+
public IntegerTokenConverter() {
}
@@ -33,7 +35,11 @@
if(o instanceof Integer) {
Integer i = (Integer) o;
return convert(i.intValue());
- }
+ }
throw new IllegalArgumentException("Cannot convert "+o+" of type"+o.getClass().getName());
}
+
+ public boolean isApplicable(Object o) {
+ return (o instanceof Integer);
+ }
}
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/MonoTypedConverter.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/MonoTypedConverter.java Thu Jul 30 18:57:14 2009
@@ -0,0 +1,20 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2009, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.core.rolling.helper;
+
+/**
+ * Converters which can deal only with one type should implement this interface.
+ *
+ * @author Ceki G&ulcu;lcü
+ *
+ */
+public interface MonoTypedConverter {
+ boolean isApplicable(Object o);
+}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/FileNamePatternTest.java Thu Jul 30 18:57:14 2009
@@ -9,13 +9,14 @@
*/
package ch.qos.logback.core.rolling.helper;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import java.util.ArrayList;
import java.util.Calendar;
+import java.util.List;
import org.junit.Test;
-
import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
@@ -64,9 +65,7 @@
@Test
// test ways for dealing with flowing i converter, as in "foo%ix"
- public void testFlowingI() {
- // System.out.println("Testing [foo%ibar%i]");
-
+ public void flowingI() {
{
FileNamePattern pp = new FileNamePattern("foo%i{}bar%i", context);
assertEquals("foo3bar3", pp.convertInt(3));
@@ -78,7 +77,7 @@
}
@Test
- public void testDate() {
+ public void date() {
Calendar cal = Calendar.getInstance();
cal.set(2003, 4, 20, 17, 55);
@@ -95,10 +94,26 @@
}
@Test
- public void testWithBackslash() {
+ public void withBackslash() {
FileNamePattern pp = new FileNamePattern("c:\\foo\\bar.%i", context);
assertEquals("c:\\foo\\bar.3", pp.convertInt(3));
}
+ @Test
+ public void objectListConverter() {
+ List<Object> oList = new ArrayList<Object>();
+
+ Calendar cal = Calendar.getInstance();
+ cal.set(2003, 4, 20, 17, 55);
+
+ oList.add(cal.getTime());
+ oList.add(79);
+
+
+ FileNamePattern fnp = new FileNamePattern("foo-%d{yyyy.MM.dd}-%i.txt", context);
+
+ assertEquals("foo-2003.05.20-79.txt", fnp.convertList(oList));
+ }
+
}
1
0

svn commit: r2381 - logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper
by noreply.ceki@qos.ch 30 Jul '09
by noreply.ceki@qos.ch 30 Jul '09
30 Jul '09
Author: ceki
Date: Thu Jul 30 18:09:05 2009
New Revision: 2381
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
Log:
Remove fluff (commented-out code)
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/FileNamePattern.java Thu Jul 30 18:09:05 2009
@@ -67,107 +67,6 @@
return pattern;
}
- // void parsex() {
- // int lastIndex = 0;
- //
- // TokenConverter tc = null;
- //
- // MAIN_LOOP: while (true) {
- // int i = pattern.indexOf('%', lastIndex);
- //
- // if (i == -1) {
- // String remainingStr = pattern.substring(lastIndex);
- //
- // // System.out.println("adding the identity token, I");
- // addTokenConverter(tc, new IdentityTokenConverter(remainingStr));
- //
- // break;
- // } else {
- // // test for degenerate case where the '%' character is at the end.
- // if (i == (patternLength - 1)) {
- // String remainingStr = pattern.substring(lastIndex);
- // addTokenConverter(tc, new IdentityTokenConverter(remainingStr));
- //
- // break;
- // }
- //
- // // System.out.println("adding the identity token, II");
- // tc = addTokenConverter(tc, new IdentityTokenConverter(pattern
- // .substring(lastIndex, i)));
- //
- // // At this stage, we can suppose that i < patternLen -1
- // char nextChar = pattern.charAt(i + 1);
- //
- // switch (nextChar) {
- // case 'i':
- // tc = addTokenConverter(tc, new IntegerTokenConverter());
- // lastIndex = i + 2;
- //
- // break; // break from switch statement
- //
- // case 'd':
- //
- // int optionEnd = getOptionEnd(i + 2);
- //
- // String option;
- //
- // if (optionEnd != -1) {
- // option = pattern.substring(i + 3, optionEnd);
- // lastIndex = optionEnd + 1;
- // } else {
- // addInfo("Assuming daily rotation schedule");
- // option = "yyyy-MM-dd";
- // lastIndex = i + 2;
- // }
- // tc = addTokenConverter(tc, new DateTokenConverter(option));
- // break; // break from switch statement
- //
- // case '%':
- // tc = addTokenConverter(tc, new IdentityTokenConverter("%"));
- // lastIndex = i + 2;
- //
- // break;
- //
- // default:
- // throw new IllegalArgumentException("The pattern[" + pattern
- // + "] does not contain a valid specifer at position " + (i + 1));
- // }
- // }
- // }
- // }
- //
- // /**
- // * Find the position of the last character of option enclosed within the
- // '{}'
- // * characters inside the pattern
- // */
- // protected int getOptionEnd(int i) {
- // // logger.debug("Char at "+i+" "+pattern.charAt(i));
- // if ((i < patternLength) && (pattern.charAt(i) == '{')) {
- // int end = pattern.indexOf('}', i);
- //
- // if (end > i) {
- // return end;
- // } else {
- // return -1;
- // }
- // }
- //
- // return -1;
- // }
- //
- // TokenConverter addTokenConverter(TokenConverter tc,
- // TokenConverter newTokenConverter) {
- // if (tc == null) {
- // tc = headTokenConverter = newTokenConverter;
- // } else {
- // tc.next = newTokenConverter;
- // tc = newTokenConverter;
- // }
- //
- // return tc;
- // }
-
public DateTokenConverter getDateTokenConverter() {
Converter p = headTokenConverter;
1
0

svn commit: r2380 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/joran/action main/java/ch/qos/logback/core/joran/spi test/java/ch/qos/logback/core/joran/spi
by noreply.ceki@qos.ch 30 Jul '09
by noreply.ceki@qos.ch 30 Jul '09
30 Jul '09
Author: ceki
Date: Thu Jul 30 15:18:40 2009
New Revision: 2380
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/NoAutoStart.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/NoAutoStartUtil.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/DoNotAutoStart.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/NoAutoStartUtilTest.java
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComplexPropertyIA.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java
Log:
- Add support for the @NoAutoStart annotation. Classes marked with this annotation will not
be auto-started by Joran (via NestedComplexPropertyIA).
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComplexPropertyIA.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComplexPropertyIA.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComplexPropertyIA.java Thu Jul 30 15:18:40 2009
@@ -15,6 +15,7 @@
import org.xml.sax.Attributes;
import ch.qos.logback.core.joran.spi.InterpretationContext;
+import ch.qos.logback.core.joran.spi.NoAutoStartUtil;
import ch.qos.logback.core.joran.spi.Pattern;
import ch.qos.logback.core.joran.spi.PropertySetter;
import ch.qos.logback.core.spi.ContextAware;
@@ -110,10 +111,11 @@
return;
}
- if(OptionHelper.isEmpty(className)) {
- addInfo("Assuming default type ["+componentClass.getName()+"] for ["+localName+"] property");
+ if (OptionHelper.isEmpty(className)) {
+ addInfo("Assuming default type [" + componentClass.getName()
+ + "] for [" + localName + "] property");
}
-
+
actionData.setNestedComplexProperty(componentClass.newInstance());
// pass along the repository
@@ -154,9 +156,13 @@
if (nestedBean.computeAggregationType("parent") == AggregationType.AS_COMPLEX_PROPERTY) {
nestedBean.setComplexProperty("parent", actionData.parentBean.getObj());
}
- // start the nested complex attribute if it implements LifeCycle
- if (actionData.getNestedComplexProperty() instanceof LifeCycle) {
- ((LifeCycle) actionData.getNestedComplexProperty()).start();
+
+ // start the nested complex property if it implements LifeCycle and is not
+ // marked with a @NoAutoStart annotation
+ Object nestedComplexProperty = actionData.getNestedComplexProperty();
+ if (nestedComplexProperty instanceof LifeCycle
+ && NoAutoStartUtil.notMarkedWithNoAutoStart(nestedComplexProperty)) {
+ ((LifeCycle) nestedComplexProperty).start();
}
Object o = ec.peekObject();
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/NoAutoStart.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/NoAutoStart.java Thu Jul 30 15:18:40 2009
@@ -0,0 +1,27 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.core.joran.spi;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * If a type (a class) has this annotation, then it will not be automatically
+ * started by Joran at configuration time.
+ *
+ * @author Ceki Gülcü
+ *
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target(ElementType.TYPE)
+public @interface NoAutoStart {
+}
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/NoAutoStartUtil.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/NoAutoStartUtil.java Thu Jul 30 15:18:40 2009
@@ -0,0 +1,21 @@
+package ch.qos.logback.core.joran.spi;
+
+public class NoAutoStartUtil {
+
+ /**
+ * Returns true if the class of the object 'o' passed as parameter is *not*
+ * marked with the NoAutoStart annotation. Return true otherwise.
+ *
+ * @param o
+ * @return true for classes not marked with the NoAutoStart annotation
+ */
+ static public boolean notMarkedWithNoAutoStart(Object o) {
+ if (o == null) {
+ return false;
+ }
+ Class<?> clazz = o.getClass();
+ NoAutoStart a = clazz.getAnnotation(NoAutoStart.class);
+ return a == null;
+ }
+
+}
Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/DoNotAutoStart.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/DoNotAutoStart.java Thu Jul 30 15:18:40 2009
@@ -0,0 +1,30 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2009, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.core.joran.spi;
+
+import ch.qos.logback.core.spi.LifeCycle;
+
+@NoAutoStart
+public class DoNotAutoStart implements LifeCycle {
+
+ boolean started = false;
+ public boolean isStarted() {
+ return started;
+ }
+
+ public void start() {
+ started = true;
+ }
+
+ public void stop() {
+ started = false;
+ }
+
+}
Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/NoAutoStartUtilTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/NoAutoStartUtilTest.java Thu Jul 30 15:18:40 2009
@@ -0,0 +1,32 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2009, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.core.joran.spi;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+
+public class NoAutoStartUtilTest {
+
+
+ @Test
+ public void commonObject() {
+ Object o = new Object();
+ assertTrue(NoAutoStartUtil.notMarkedWithNoAutoStart(o));
+ }
+
+ @Test
+ public void markedWithNoAutoStart() {
+ DoNotAutoStart o = new DoNotAutoStart();
+ assertFalse(NoAutoStartUtil.notMarkedWithNoAutoStart(o));
+ }
+}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java Thu Jul 30 15:18:40 2009
@@ -15,6 +15,7 @@
@RunWith(Suite.class)
@SuiteClasses( { PatternTest.class, SimpleStoreTest.class,
- PropertySetterTest.class, DefaultNestedComponentRegistryTest.class })
+ PropertySetterTest.class, NoAutoStartUtilTest.class,
+ DefaultNestedComponentRegistryTest.class })
public class PackageTest {
}
1
0

svn commit: r2379 - logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling
by noreply.ceki@qos.ch 30 Jul '09
by noreply.ceki@qos.ch 30 Jul '09
30 Jul '09
Author: ceki
Date: Thu Jul 30 14:38:23 2009
New Revision: 2379
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
Log:
- minor change in the order of code invocation
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java Thu Jul 30 14:38:23 2009
@@ -52,9 +52,6 @@
// set the LR for our utility object
renameUtil.setContext(this.context);
- timeBasedTriggering.setContext(context);
- timeBasedTriggering.setTimeBasedRollingPolicy(this);
-
// find out period from the filename pattern
if (fileNamePatternStr != null) {
fileNamePattern = new FileNamePattern(fileNamePatternStr, this.context);
@@ -75,6 +72,8 @@
addInfo("Will use the pattern " + fileNamePatternWCS
+ " for the active file");
+ timeBasedTriggering.setContext(context);
+ timeBasedTriggering.setTimeBasedRollingPolicy(this);
timeBasedTriggering.start();
if (maxHistory != NO_DELETE_HISTORY) {
1
0

svn commit: r2378 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/rolling main/java/ch/qos/logback/core/spi test/java/ch/qos/logback/core/rolling
by noreply.ceki@qos.ch 30 Jul '09
by noreply.ceki@qos.ch 30 Jul '09
30 Jul '09
Author: ceki
Date: Thu Jul 30 14:12:28 2009
New Revision: 2378
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java
- copied, changed from r2376, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedTriggeringPolicy.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicy.java
- copied, changed from r2376, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/NamingAndTriggeringPolicy.java
Removed:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedTriggeringPolicy.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/NamingAndTriggeringPolicy.java
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAware.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java
Log:
Further refactoring of TimeBasedRollingPolicy. Most of the work
related to triggering has moved into an interface called
TimedBasedFileNamingAndTriggeringPolicy. Related to LBCORE-61.
The file attribute in RollingFileAppender is honored once again. This
reverts the changes in revision 2376. Relevant tests in
TimeBasedRollingTest have been resuscitated.
Copied: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java (from r2376, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedTriggeringPolicy.java)
==============================================================================
--- /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedTriggeringPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedFileNamingAndTriggeringPolicy.java Thu Jul 30 14:12:28 2009
@@ -4,98 +4,118 @@
import java.util.Date;
import ch.qos.logback.core.rolling.helper.DateTokenConverter;
-import ch.qos.logback.core.rolling.helper.FileNamePattern;
import ch.qos.logback.core.rolling.helper.RollingCalendar;
import ch.qos.logback.core.spi.ContextAwareBase;
-public class DefaultTimeBasedTriggeringPolicy<E> extends ContextAwareBase
- implements NamingAndTriggeringPolicy<E> {
+public class DefaultTimeBasedFileNamingAndTriggeringPolicy<E> extends ContextAwareBase
+ implements TimeBasedFileNamingAndTriggeringPolicy<E> {
- FileNamePattern fileNamePattern;
- String elapsedPeriodsFileName;
- FileNamePattern activeFileNamePattern;
- RollingCalendar rc;
- long currentTime;
- long nextCheck;
+ private TimeBasedRollingPolicy<E> tbrp;
+ private String elapsedPeriodsFileName;
+ private RollingCalendar rc;
+ private long currentTime;
+ private long nextCheck;
// indicate whether the time has been forced or not
- boolean isTimeForced = false;
- Date lastCheck = null;
+ private boolean isTimeForced = false;
+ private Date dateInCurrentPeriod = null;
boolean started = false;
- public void setCurrentTime(long timeInMillis) {
- currentTime = timeInMillis;
- isTimeForced = true;
- }
-
- public long getCurrentTime() {
- // if time is forced return the time set by user
- if (isTimeForced) {
- return currentTime;
- } else {
- return System.currentTimeMillis();
- }
- }
-
public boolean isStarted() {
return started;
}
public void start() {
- DateTokenConverter dtc = fileNamePattern.getDateTokenConverter();
+ DateTokenConverter dtc = tbrp.fileNamePattern.getDateTokenConverter();
if (dtc == null) {
throw new IllegalStateException("FileNamePattern ["
- + fileNamePattern.getPattern()
+ + tbrp.fileNamePattern.getPattern()
+ "] does not contain a valid DateToken");
}
rc = new RollingCalendar();
rc.init(dtc.getDatePattern());
addInfo("The date pattern is '" + dtc.getDatePattern()
- + "' from file name pattern '" + fileNamePattern.getPattern() + "'.");
+ + "' from file name pattern '" + tbrp.fileNamePattern.getPattern()
+ + "'.");
rc.printPeriodicity(this);
- // lastCheck can be set by test classes
+ // dateInCurrentPeriod can be set by test classes
// if it has not been set, we set it here
- if (lastCheck == null) {
- lastCheck = new Date();
- lastCheck.setTime(getCurrentTime());
+ if (dateInCurrentPeriod == null) {
+ dateInCurrentPeriod = new Date();
+ updateDateInCurrentPeriod(getCurrentTime());
}
- nextCheck = rc.getNextTriggeringMillis(lastCheck);
-
+ computeNextCheck();
}
-
+
public void stop() {
started = false;
}
+
+ private void computeNextCheck() {
+ nextCheck = rc.getNextTriggeringMillis(dateInCurrentPeriod);
+ }
- // allow Test classes to act on the lastCheck field to simulate old
+ // allow Test classes to act on the dateInCurrentPeriod field to simulate old
// log files needing rollover
- void setLastCheck(Date _lastCheck) {
- this.lastCheck = _lastCheck;
+ public void setDateInCurrentPeriod(Date _dateInCurrentPeriod) {
+ this.dateInCurrentPeriod = _dateInCurrentPeriod;
+ }
+
+ public Date getDateInCurrentPeriod() {
+ return dateInCurrentPeriod;
}
public String getElapsedPeriodsFileName() {
return elapsedPeriodsFileName;
}
+ public String getCurrentPeriodsFileNameWithoutCompressionSuffix() {
+ return tbrp.fileNamePatternWCS.convertDate(dateInCurrentPeriod);
+ }
+
public boolean isTriggeringEvent(File activeFile, final E event) {
long time = getCurrentTime();
if (time >= nextCheck) {
- // We set the elapsedPeriodsFileName before we set the 'lastCheck'
- // variable
- // The elapsedPeriodsFileName corresponds to the file name of the period
- // that just elapsed.
- elapsedPeriodsFileName = activeFileNamePattern.convertDate(lastCheck);
-
- lastCheck.setTime(time);
- nextCheck = rc.getNextTriggeringMillis(lastCheck);
+ Date dateInElapsedPeriod = dateInCurrentPeriod;
+ elapsedPeriodsFileName = tbrp.fileNamePatternWCS
+ .convertDate(dateInElapsedPeriod);
+ updateDateInCurrentPeriod(time);
+ computeNextCheck();
return true;
} else {
return false;
}
}
+ private void updateDateInCurrentPeriod(long now) {
+ dateInCurrentPeriod.setTime(now);
+ }
+
+ public void setCurrentTime(long timeInMillis) {
+ currentTime = timeInMillis;
+ isTimeForced = true;
+ }
+
+ public long getCurrentTime() {
+ // if time is forced return the time set by user
+ if (isTimeForced) {
+ return currentTime;
+ } else {
+ return System.currentTimeMillis();
+ }
+ }
+
+ public void setTimeBasedRollingPolicy(TimeBasedRollingPolicy<E> _tbrp) {
+ this.tbrp = _tbrp;
+
+ }
+
+ public RollingCalendar getRollingCalendar() {
+ return rc;
+ }
+
}
Copied: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicy.java (from r2376, /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/NamingAndTriggeringPolicy.java)
==============================================================================
--- /logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/NamingAndTriggeringPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedFileNamingAndTriggeringPolicy.java Thu Jul 30 14:12:28 2009
@@ -10,7 +10,73 @@
package ch.qos.logback.core.rolling;
-public interface NamingAndTriggeringPolicy<E> extends TriggeringPolicy<E> {
+import java.util.Date;
+import ch.qos.logback.core.rolling.helper.RollingCalendar;
+import ch.qos.logback.core.spi.ContextAware;
+
+/**
+ * This interface lists the set of methods that need to be implemented by
+ * triggering policies which are nested within a {@link TimeBasedRollingPolicy}.
+ *
+ * @author Ceki Gülcü
+ *
+ * @param <E>
+ */
+public interface TimeBasedFileNamingAndTriggeringPolicy<E> extends
+ TriggeringPolicy<E>, ContextAware {
+
+ /**
+ * Set the host/parent {@link TimeBasedRollingPolicy}.
+ *
+ * @param the
+ * parent TimeBasedRollingPolicy
+ */
+ void setTimeBasedRollingPolicy(TimeBasedRollingPolicy<E> tbrp);
+
+ /**
+ * Return the file name for the elapsed periods file name.
+ *
+ * @return
+ */
String getElapsedPeriodsFileName();
+
+ /**
+ * Return the current periods file name without the compression suffix. This
+ * value is equivalent to the active file name.
+ *
+ * @return current period's file name (without compression suffix)
+ */
+ String getCurrentPeriodsFileNameWithoutCompressionSuffix();
+
+ /**
+ * Return the rolling calendar used by this instance.
+ *
+ * @return
+ */
+ RollingCalendar getRollingCalendar();
+
+ /**
+ * Return the current time which is usually the value returned by
+ * System.currentMillis(). However, for <b>testing</b> purposed this value
+ * may be different than the real time.
+ *
+ * @return current time value
+ */
+ long getCurrentTime();
+
+ /**
+ * Set the current time. Only unit tests should invoke this method.
+ *
+ * @param now
+ */
+ void setCurrentTime(long now);
+
+ /**
+ * Set some date in the current period. Only unit tests should invoke this
+ * method.
+ *
+ * @param date
+ */
+ void setDateInCurrentPeriod(Date date);
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java Thu Jul 30 14:12:28 2009
@@ -1,7 +1,7 @@
/**
* Logback: the reliable, generic, fast and flexible logging framework.
*
- * Copyright (C) 1999-2006, QOS.ch
+ * Copyright (C) 1999-2009, QOS.ch
*
* This library is free software, you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
@@ -36,40 +36,28 @@
static final String FNP_NOT_SET = "The FileNamePattern option must be set before using TimeBasedRollingPolicy. ";
static final int NO_DELETE_HISTORY = 0;
- FileNamePattern activeFileNamePattern;
- Compressor compressor;
- RenameUtil renameUtil = new RenameUtil();
+ // WCS: without compression suffix
+ FileNamePattern fileNamePatternWCS;
+
+ private Compressor compressor;
+ private RenameUtil renameUtil = new RenameUtil();
Future<?> future;
- int maxHistory = NO_DELETE_HISTORY;
- TimeBasedCleaner tbCleaner;
+ private int maxHistory = NO_DELETE_HISTORY;
+ private TimeBasedCleaner tbCleaner;
- DefaultTimeBasedTriggeringPolicy<E> timeBasedTriggering = new DefaultTimeBasedTriggeringPolicy<E>();
-
-// public void setCurrentTime(long timeInMillis) {
-// currentTime = timeInMillis;
-// isTimeForced = true;
-// }
-//
-// public long getCurrentTime() {
-// // if time is forced return the time set by user
-// if (isTimeForced) {
-// return currentTime;
-// } else {
-// return System.currentTimeMillis();
-// }
-// }
+ TimeBasedFileNamingAndTriggeringPolicy<E> timeBasedTriggering = new DefaultTimeBasedFileNamingAndTriggeringPolicy<E>();
public void start() {
// set the LR for our utility object
renameUtil.setContext(this.context);
timeBasedTriggering.setContext(context);
+ timeBasedTriggering.setTimeBasedRollingPolicy(this);
// find out period from the filename pattern
if (fileNamePatternStr != null) {
fileNamePattern = new FileNamePattern(fileNamePatternStr, this.context);
- timeBasedTriggering.fileNamePattern = fileNamePattern;
determineCompressionMode();
} else {
addWarn(FNP_NOT_SET);
@@ -78,54 +66,45 @@
+ CoreConstants.SEE_FNP_NOT_SET);
}
-
compressor = new Compressor(compressionMode);
compressor.setContext(context);
- int len = fileNamePatternStr.length();
- switch (compressionMode) {
- case GZ:
- activeFileNamePattern = new FileNamePattern(fileNamePatternStr.substring(
- 0, len - 3), this.context);
- ;
- break;
- case ZIP:
- activeFileNamePattern = new FileNamePattern(fileNamePatternStr.substring(
- 0, len - 4), this.context);
- break;
- case NONE:
- activeFileNamePattern = fileNamePattern;
- }
-
- addInfo("Will use the pattern " + activeFileNamePattern
+ fileNamePatternWCS = new FileNamePattern(computeFileNameStr_WCS(fileNamePatternStr,
+ compressionMode), this.context);
+
+ addInfo("Will use the pattern " + fileNamePatternWCS
+ " for the active file");
- timeBasedTriggering.activeFileNamePattern = activeFileNamePattern;
timeBasedTriggering.start();
-
+
if (maxHistory != NO_DELETE_HISTORY) {
- tbCleaner = new TimeBasedCleaner(fileNamePattern, timeBasedTriggering.rc, maxHistory);
+ tbCleaner = new TimeBasedCleaner(fileNamePattern, timeBasedTriggering.getRollingCalendar(),
+ maxHistory);
}
}
-
- public long getCurrentTime() {
- return timeBasedTriggering.getCurrentTime();
- }
- public void setCurrentTime(long timeInMillis) {
- timeBasedTriggering.setCurrentTime(timeInMillis);
- }
- void setLastCheck(Date _lastCheck) {
- timeBasedTriggering.setLastCheck(_lastCheck);
+ static String computeFileNameStr_WCS(String fileNamePatternStr,
+ CompressionMode compressionMode) {
+ int len = fileNamePatternStr.length();
+ switch (compressionMode) {
+ case GZ:
+ return fileNamePatternStr.substring(0, len - 3);
+ case ZIP:
+ return fileNamePatternStr.substring(0, len - 4);
+ case NONE:
+ return fileNamePatternStr;
+ }
+ throw new IllegalStateException("Execution should not reach this point");
}
-
+
public void rollover() throws RolloverFailure {
// when rollover is called the elapsed period's file has
// been already closed. This is a working assumption of this method.
- String elapsedPeriodsFileName = timeBasedTriggering.getElapsedPeriodsFileName();
-
+ String elapsedPeriodsFileName = timeBasedTriggering
+ .getElapsedPeriodsFileName();
+
if (compressionMode == CompressionMode.NONE) {
if (getParentsRawFileProperty() != null) {
renameUtil.rename(getParentsRawFileProperty(), elapsedPeriodsFileName);
@@ -143,14 +122,14 @@
}
}
- Future asyncCompress(String nameOfFile2Compress,
- String nameOfCompressedFile) throws RolloverFailure {
+ Future asyncCompress(String nameOfFile2Compress, String nameOfCompressedFile)
+ throws RolloverFailure {
AsynchronousCompressor ac = new AsynchronousCompressor(compressor);
- return ac.compressAsynchronously(nameOfFile2Compress,
- nameOfCompressedFile);
+ return ac.compressAsynchronously(nameOfFile2Compress, nameOfCompressedFile);
}
- Future renamedRawAndAsyncCompress(String nameOfCompressedFile) throws RolloverFailure {
+ Future renamedRawAndAsyncCompress(String nameOfCompressedFile)
+ throws RolloverFailure {
String parentsRawFile = getParentsRawFileProperty();
String tmpTarget = parentsRawFile + System.nanoTime() + ".tmp";
renameUtil.rename(parentsRawFile, tmpTarget);
@@ -178,35 +157,16 @@
*
*/
public String getActiveFileName() {
-
- return activeFileNamePattern.convertDate(timeBasedTriggering.lastCheck);
-
+ String parentsRawFileProperty = getParentsRawFileProperty();
+ if (parentsRawFileProperty != null) {
+ return parentsRawFileProperty;
+ } else {
+ return timeBasedTriggering.getCurrentPeriodsFileNameWithoutCompressionSuffix();
+ }
}
-// // get the active file name for the current (latest) period
-// private String getLatestPeriodsFileName() {
-// return activeFileNamePattern.convertDate(lastCheck);
-// }
-
public boolean isTriggeringEvent(File activeFile, final E event) {
-
return timeBasedTriggering.isTriggeringEvent(activeFile, event);
-
-// long time = getCurrentTime();
-//
-// if (time >= nextCheck) {
-// // We set the elapsedPeriodsFileName before we set the 'lastCheck'
-// // variable
-// // The elapsedPeriodsFileName corresponds to the file name of the period
-// // that just elapsed.
-// elapsedPeriodsFileName = activeFileNamePattern.convertDate(lastCheck);
-//
-// lastCheck.setTime(time);
-// nextCheck = rc.getNextTriggeringMillis(lastCheck);
-// return true;
-// } else {
-// return false;
-// }
}
/**
@@ -232,5 +192,4 @@
public String toString() {
return "c.q.l.core.rolling.TimeBasedRollingPolicy";
}
-
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAware.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAware.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAware.java Thu Jul 30 14:12:28 2009
@@ -1,11 +1,11 @@
/**
- * LOGBack: the reliable, fast and flexible logging library for Java.
- *
- * Copyright (C) 1999-2006, QOS.ch
- *
- * This library is free software, you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation.
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2009, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
*/
package ch.qos.logback.core.spi;
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java Thu Jul 30 14:12:28 2009
@@ -108,9 +108,9 @@
tbrp.setContext(context);
tbrp.setFileNamePattern(filenamePattern);
tbrp.setParent(rfa);
- tbrp.setCurrentTime(givenTime);
+ tbrp.timeBasedTriggering.setCurrentTime(givenTime);
if (lastCheck != 0) {
- tbrp.setLastCheck(new Date(lastCheck));
+ tbrp.timeBasedTriggering.setDateInCurrentPeriod(new Date(lastCheck));
}
rfa.setRollingPolicy(tbrp);
tbrp.start();
@@ -131,13 +131,13 @@
addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
incCurrentTime(1100);
- tbrp1.setCurrentTime(currentTime);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
for (int i = 0; i < 3; i++) {
rfa1.doAppend("Hello---" + i);
addExpectedFileNamedIfItsTime_ByDate(testId, false);
incCurrentTime(500);
- tbrp1.setCurrentTime(currentTime);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
}
int i = 0;
@@ -159,14 +159,14 @@
addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), true);
incCurrentTime(1100);
- tbrp1.setCurrentTime(currentTime);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
for (int i = 0; i < 3; i++) {
// when i == 2, file name should not have .gz extension
addExpectedFileNamedIfItsTime_ByDate(testId, i != 2);
rfa1.doAppend("Hello---" + i);
incCurrentTime(500);
- tbrp1.setCurrentTime(currentTime);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
}
tbrp1.future.get(2000, TimeUnit.MILLISECONDS);
@@ -194,26 +194,26 @@
addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
incCurrentTime(1100);
- tbrp1.setCurrentTime(currentTime);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
for (int i = 0; i <= 2; i++) {
rfa1.doAppend("Hello---" + i);
addExpectedFileNamedIfItsTime_ByDate(testId, false);
incCurrentTime(500);
- tbrp1.setCurrentTime(currentTime);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
}
rfa1.stop();
initRFA(rfa2, null);
initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
- + DATE_PATTERN + "}", tbrp1.getCurrentTime(), 0);
+ + DATE_PATTERN + "}", tbrp1.timeBasedTriggering.getCurrentTime(), 0);
for (int i = 0; i <= 2; i++) {
addExpectedFileNamedIfItsTime_ByDate(testId, false);
rfa2.doAppend("World---" + i);
incCurrentTime(100);
- tbrp2.setCurrentTime(currentTime);
+ tbrp2.timeBasedTriggering.setCurrentTime(currentTime);
}
int i = 0;
@@ -222,165 +222,165 @@
+ "witness/rolling/tbr-" + testId + "." + i++));
}
}
-//
-// /**
-// * Without compression, file option set, with stop/restart
-// */
-// @Test
-// public void noCompression_FileSet_StopRestart_4() throws Exception {
-// String testId = "test4";
-// initRFA(rfa1, testId2FileName(testId));
-// initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-// + DATE_PATTERN + "}", currentTime, 0);
-//
-// addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
-//
-// incCurrentTime(1100);
-// tbrp1.setCurrentTime(currentTime);
-//
-// for (int i = 0; i <= 2; i++) {
-// rfa1.doAppend("Hello---" + i);
-// addExpectedFileNamedIfItsTime_ByDate(testId, false);
-// incCurrentTime(500);
-// tbrp1.setCurrentTime(currentTime);
-// }
-//
-// rfa1.stop();
-//
-// initRFA(rfa2, testId2FileName(testId));
-// initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-// + DATE_PATTERN + "}", currentTime, currentTime);
-//
-// for (int i = 0; i <= 2; i++) {
-// rfa2.doAppend("World---" + i);
-// addExpectedFileNamedIfItsTime_ByDate(testId, false);
-// incCurrentTime(100);
-// tbrp2.setCurrentTime(currentTime);
-// }
-//
-// massageExpectedFilesToCorresponToCurrentTarget("test4.log");
-//
-// int i = 0;
-// for (String fn : expectedFilenameList) {
-// assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
-// + "witness/rolling/tbr-" + testId + "." + i++));
-// }
-// }
-//
-// @Test
-// public void noCompression_FileSet_StopRestart_WithLongWait_4B()
-// throws Exception {
-// String testId = "test4B";
-// initRFA(rfa1, testId2FileName(testId));
-// initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-// + DATE_PATTERN + "}", currentTime, 0);
-//
-// addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
-//
-// incCurrentTime(1100);
-// tbrp1.setCurrentTime(currentTime);
-//
-// for (int i = 0; i <= 2; i++) {
-// rfa1.doAppend("Hello---" + i);
-// addExpectedFileNamedIfItsTime_ByDate(testId, false);
-// incCurrentTime(500);
-// tbrp1.setCurrentTime(currentTime);
-// }
-//
-// rfa1.stop();
-//
-// long fileTimestamp = currentTime;
-// incCurrentTime(2000);
-//
-// initRFA(rfa2, CoreTestConstants.OUTPUT_DIR_PREFIX + "test4B.log");
-// initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId +"-%d{"
-// + DATE_PATTERN + "}", currentTime, fileTimestamp);
-//
-// for (int i = 0; i <= 2; i++) {
-// rfa2.doAppend("World---" + i);
-// addExpectedFileNamedIfItsTime_ByDate(testId, false);
-// incCurrentTime(100);
-// tbrp2.setCurrentTime(currentTime);
-// }
-//
-// massageExpectedFilesToCorresponToCurrentTarget("test4B.log");
-//
-// int i = 0;
-// for (String fn : expectedFilenameList) {
-// assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
-// + "witness/rolling/tbr-test4B." + i++));
-// }
-//
-// }
-//
-// /**
-// * No compression, file option set, without stop/restart
-// */
-// @Test
-// public void noCompression_FileSet_NoRestart_5() throws Exception {
-// String testId = "test5";
-//
-// initRFA(rfa1, testId2FileName(testId));
-// initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-// + DATE_PATTERN + "}", currentTime, 0);
-//
-// addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
-//
-// incCurrentTime(1100);
-// tbrp1.setCurrentTime(currentTime);
-//
-// for (int i = 0; i < 3; i++) {
-// rfa1.doAppend("Hello---" + i);
-// addExpectedFileNamedIfItsTime_ByDate(testId, false);
-// incCurrentTime(500);
-// tbrp1.setCurrentTime(currentTime);
-// }
-//
-// massageExpectedFilesToCorresponToCurrentTarget("test5.log");
-//
-// int i = 0;
-// for (String fn : expectedFilenameList) {
-// assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
-// + "witness/rolling/tbr-test5." + i++));
-// }
-// }
-//
-// /**
-// * With compression, file option set, no stop/restart,
-// */
-// @Test
-// public void withCompression_FileSet_NoRestart_6() throws Exception {
-//
-// String testId = "test6";
-//
-// initRFA(rfa1, testId2FileName(testId));
-// initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
-// + DATE_PATTERN + "}.gz", currentTime, 0);
-//
-// addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), true);
-//
-// incCurrentTime(1100);
-// tbrp1.setCurrentTime(currentTime);
-//
-// for (int i = 0; i < 3; i++) {
-// rfa1.doAppend("Hello---" + i);
-// addExpectedFileNamedIfItsTime_ByDate(testId, true);
-// incCurrentTime(500);
-// tbrp1.setCurrentTime(currentTime);
-// }
-//
-// // wait for the compression task to finish
-// tbrp1.future.get(1000, TimeUnit.MILLISECONDS);
-//
-// massageExpectedFilesToCorresponToCurrentTarget("test6.log");
-//
-// int i = 0;
-// for (String fn : expectedFilenameList) {
-// assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
-// + "witness/rolling/tbr-" + testId + "." + i + addGZIfNotLast(i)));
-// i++;
-// }
-// }
+
+ /**
+ * Without compression, file option set, with stop/restart
+ */
+ @Test
+ public void noCompression_FileSet_StopRestart_4() throws Exception {
+ String testId = "test4";
+ initRFA(rfa1, testId2FileName(testId));
+ initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+ + DATE_PATTERN + "}", currentTime, 0);
+
+ addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
+
+ incCurrentTime(1100);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+
+ for (int i = 0; i <= 2; i++) {
+ rfa1.doAppend("Hello---" + i);
+ addExpectedFileNamedIfItsTime_ByDate(testId, false);
+ incCurrentTime(500);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+ }
+
+ rfa1.stop();
+
+ initRFA(rfa2, testId2FileName(testId));
+ initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+ + DATE_PATTERN + "}", currentTime, currentTime);
+
+ for (int i = 0; i <= 2; i++) {
+ rfa2.doAppend("World---" + i);
+ addExpectedFileNamedIfItsTime_ByDate(testId, false);
+ incCurrentTime(100);
+ tbrp2.timeBasedTriggering.setCurrentTime(currentTime);
+ }
+
+ massageExpectedFilesToCorresponToCurrentTarget("test4.log");
+
+ int i = 0;
+ for (String fn : expectedFilenameList) {
+ assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+ + "witness/rolling/tbr-" + testId + "." + i++));
+ }
+ }
+
+ @Test
+ public void noCompression_FileSet_StopRestart_WithLongWait_4B()
+ throws Exception {
+ String testId = "test4B";
+ initRFA(rfa1, testId2FileName(testId));
+ initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+ + DATE_PATTERN + "}", currentTime, 0);
+
+ addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
+
+ incCurrentTime(1100);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+
+ for (int i = 0; i <= 2; i++) {
+ rfa1.doAppend("Hello---" + i);
+ addExpectedFileNamedIfItsTime_ByDate(testId, false);
+ incCurrentTime(500);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+ }
+
+ rfa1.stop();
+
+ long fileTimestamp = currentTime;
+ incCurrentTime(2000);
+
+ initRFA(rfa2, CoreTestConstants.OUTPUT_DIR_PREFIX + "test4B.log");
+ initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId +"-%d{"
+ + DATE_PATTERN + "}", currentTime, fileTimestamp);
+
+ for (int i = 0; i <= 2; i++) {
+ rfa2.doAppend("World---" + i);
+ addExpectedFileNamedIfItsTime_ByDate(testId, false);
+ incCurrentTime(100);
+ tbrp2.timeBasedTriggering.setCurrentTime(currentTime);
+ }
+
+ massageExpectedFilesToCorresponToCurrentTarget("test4B.log");
+
+ int i = 0;
+ for (String fn : expectedFilenameList) {
+ assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+ + "witness/rolling/tbr-test4B." + i++));
+ }
+
+ }
+
+ /**
+ * No compression, file option set, without stop/restart
+ */
+ @Test
+ public void noCompression_FileSet_NoRestart_5() throws Exception {
+ String testId = "test5";
+
+ initRFA(rfa1, testId2FileName(testId));
+ initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+ + DATE_PATTERN + "}", currentTime, 0);
+
+ addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
+
+ incCurrentTime(1100);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+
+ for (int i = 0; i < 3; i++) {
+ rfa1.doAppend("Hello---" + i);
+ addExpectedFileNamedIfItsTime_ByDate(testId, false);
+ incCurrentTime(500);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+ }
+
+ massageExpectedFilesToCorresponToCurrentTarget("test5.log");
+
+ int i = 0;
+ for (String fn : expectedFilenameList) {
+ assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+ + "witness/rolling/tbr-test5." + i++));
+ }
+ }
+
+ /**
+ * With compression, file option set, no stop/restart,
+ */
+ @Test
+ public void withCompression_FileSet_NoRestart_6() throws Exception {
+
+ String testId = "test6";
+
+ initRFA(rfa1, testId2FileName(testId));
+ initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+ + DATE_PATTERN + "}.gz", currentTime, 0);
+
+ addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), true);
+
+ incCurrentTime(1100);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+
+ for (int i = 0; i < 3; i++) {
+ rfa1.doAppend("Hello---" + i);
+ addExpectedFileNamedIfItsTime_ByDate(testId, true);
+ incCurrentTime(500);
+ tbrp1.timeBasedTriggering.setCurrentTime(currentTime);
+ }
+
+ // wait for the compression task to finish
+ tbrp1.future.get(1000, TimeUnit.MILLISECONDS);
+
+ massageExpectedFilesToCorresponToCurrentTarget("test6.log");
+
+ int i = 0;
+ for (String fn : expectedFilenameList) {
+ assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+ + "witness/rolling/tbr-" + testId + "." + i + addGZIfNotLast(i)));
+ i++;
+ }
+ }
// =========================================================================
// utility methods
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingWithCleanTest.java Thu Jul 30 14:12:28 2009
@@ -78,14 +78,14 @@
tbrp.setMaxHistory(maxHistory);
tbrp.setParent(rfa);
- tbrp.setCurrentTime(currentTime);
+ tbrp.timeBasedTriggering.setCurrentTime(currentTime);
tbrp.start();
rfa.setRollingPolicy(tbrp);
rfa.start();
for (int i = 0; i < maxHistory * 3; i++) {
rfa.doAppend("Hello---" + i);
- tbrp.setCurrentTime(addTime(tbrp.getCurrentTime(), delay / 2));
+ tbrp.timeBasedTriggering.setCurrentTime(addTime(tbrp.timeBasedTriggering.getCurrentTime(), delay / 2));
if (tbrp.future != null) {
tbrp.future.get(200, TimeUnit.MILLISECONDS);
}
1
0

svn commit: r2377 - in logback/trunk: logback-access/src/test/java/ch/qos/logback/access/db logback-classic/src/test/java/ch/qos/logback/classic/db
by noreply.ceki@qos.ch 30 Jul '09
by noreply.ceki@qos.ch 30 Jul '09
30 Jul '09
Author: ceki
Date: Thu Jul 30 11:40:46 2009
New Revision: 2377
Modified:
logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderIntegrationTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java
Log:
Ignore oracle in tests
Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderIntegrationTest.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderIntegrationTest.java (original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderIntegrationTest.java Thu Jul 30 11:40:46 2009
@@ -90,6 +90,7 @@
}
@Test
+ @Ignore
public void oracle10g() throws Exception {
// perform test only on conforming hosts
if (!isConformingHostAndJDK16OrHigher()) {
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java Thu Jul 30 11:40:46 2009
@@ -92,6 +92,7 @@
}
@Test
+ @Ignore
public void oracle10g() throws Exception {
// perform test only on conforming hosts
if (!isConformingHostAndJDK16OrHigher()) {
1
0

[JIRA] Created: (LBCLASSIC-144) if debug=true, then in case of errors status messages are printed twice
by Ceki Gulcu (JIRA) 27 Jul '09
by Ceki Gulcu (JIRA) 27 Jul '09
27 Jul '09
if debug=true, then in case of errors status messages are printed twice
-----------------------------------------------------------------------
Key: LBCLASSIC-144
URL: http://jira.qos.ch/browse/LBCLASSIC-144
Project: logback-classic
Issue Type: Bug
Components: joran
Reporter: Ceki Gulcu
Assignee: Logback dev list
Priority: Minor
If the debug attribute in <configuration> is set to true, in case of errors status messages are printed twice
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
1
0

svn commit: r2376 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/rolling test/java/ch/qos/logback/core/rolling test/witness/rolling
by noreply.ceki@qos.ch 24 Jul '09
by noreply.ceki@qos.ch 24 Jul '09
24 Jul '09
Author: ceki
Date: Fri Jul 24 10:07:40 2009
New Revision: 2376
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedTriggeringPolicy.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/NamingAndTriggeringPolicy.java
logback/trunk/logback-core/src/test/witness/rolling/tbr-test2.0.gz (contents, props changed)
logback/trunk/logback-core/src/test/witness/rolling/tbr-test2.1.gz (contents, props changed)
logback/trunk/logback-core/src/test/witness/rolling/tbr-test2.2
logback/trunk/logback-core/src/test/witness/rolling/tbr-test3.0
- copied unchanged from r2372, /logback/trunk/logback-core/src/test/witness/rolling/tbr-test2.0
logback/trunk/logback-core/src/test/witness/rolling/tbr-test3.1
- copied unchanged from r2372, /logback/trunk/logback-core/src/test/witness/rolling/tbr-test2.1
logback/trunk/logback-core/src/test/witness/rolling/tbr-test3.2
- copied unchanged from r2372, /logback/trunk/logback-core/src/test/witness/rolling/tbr-test2.2
logback/trunk/logback-core/src/test/witness/rolling/tbr-test3.3
- copied unchanged from r2372, /logback/trunk/logback-core/src/test/witness/rolling/tbr-test2.3
Removed:
logback/trunk/logback-core/src/test/witness/rolling/tbr-test2.0
logback/trunk/logback-core/src/test/witness/rolling/tbr-test2.1
logback/trunk/logback-core/src/test/witness/rolling/tbr-test2.3
logback/trunk/logback-core/src/test/witness/rolling/tbr-test3.0.gz
logback/trunk/logback-core/src/test/witness/rolling/tbr-test3.1.gz
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
Log:
Significant refactoring of TimeBasedRollingPolicy. Most of the work related to triggerring has
moved a new class called DefaultTimedBasedTriggeringPolicy. Related to LBCORE-61.
The File attribute of RollingFileAppender is _now_ ignored! As a consequence,
3 tests in TimeBasedRollingTest have been removed/disabled.
WARNING: ongoing and unpolished work.
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedTriggeringPolicy.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/DefaultTimeBasedTriggeringPolicy.java Fri Jul 24 10:07:40 2009
@@ -0,0 +1,101 @@
+package ch.qos.logback.core.rolling;
+
+import java.io.File;
+import java.util.Date;
+
+import ch.qos.logback.core.rolling.helper.DateTokenConverter;
+import ch.qos.logback.core.rolling.helper.FileNamePattern;
+import ch.qos.logback.core.rolling.helper.RollingCalendar;
+import ch.qos.logback.core.spi.ContextAwareBase;
+
+public class DefaultTimeBasedTriggeringPolicy<E> extends ContextAwareBase
+ implements NamingAndTriggeringPolicy<E> {
+
+ FileNamePattern fileNamePattern;
+ String elapsedPeriodsFileName;
+ FileNamePattern activeFileNamePattern;
+ RollingCalendar rc;
+ long currentTime;
+ long nextCheck;
+ // indicate whether the time has been forced or not
+ boolean isTimeForced = false;
+ Date lastCheck = null;
+ boolean started = false;
+
+ public void setCurrentTime(long timeInMillis) {
+ currentTime = timeInMillis;
+ isTimeForced = true;
+ }
+
+ public long getCurrentTime() {
+ // if time is forced return the time set by user
+ if (isTimeForced) {
+ return currentTime;
+ } else {
+ return System.currentTimeMillis();
+ }
+ }
+
+ public boolean isStarted() {
+ return started;
+ }
+
+ public void start() {
+
+ DateTokenConverter dtc = fileNamePattern.getDateTokenConverter();
+
+ if (dtc == null) {
+ throw new IllegalStateException("FileNamePattern ["
+ + fileNamePattern.getPattern()
+ + "] does not contain a valid DateToken");
+ }
+
+ rc = new RollingCalendar();
+ rc.init(dtc.getDatePattern());
+ addInfo("The date pattern is '" + dtc.getDatePattern()
+ + "' from file name pattern '" + fileNamePattern.getPattern() + "'.");
+ rc.printPeriodicity(this);
+
+ // lastCheck can be set by test classes
+ // if it has not been set, we set it here
+ if (lastCheck == null) {
+ lastCheck = new Date();
+ lastCheck.setTime(getCurrentTime());
+ }
+ nextCheck = rc.getNextTriggeringMillis(lastCheck);
+
+ }
+
+ public void stop() {
+ started = false;
+ }
+
+ // allow Test classes to act on the lastCheck field to simulate old
+ // log files needing rollover
+ void setLastCheck(Date _lastCheck) {
+ this.lastCheck = _lastCheck;
+ }
+
+ public String getElapsedPeriodsFileName() {
+ return elapsedPeriodsFileName;
+ }
+
+ public boolean isTriggeringEvent(File activeFile, final E event) {
+ long time = getCurrentTime();
+
+ if (time >= nextCheck) {
+ // We set the elapsedPeriodsFileName before we set the 'lastCheck'
+ // variable
+ // The elapsedPeriodsFileName corresponds to the file name of the period
+ // that just elapsed.
+ elapsedPeriodsFileName = activeFileNamePattern.convertDate(lastCheck);
+
+ lastCheck.setTime(time);
+ nextCheck = rc.getNextTriggeringMillis(lastCheck);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+}
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/NamingAndTriggeringPolicy.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/NamingAndTriggeringPolicy.java Fri Jul 24 10:07:40 2009
@@ -0,0 +1,16 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2009, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+
+package ch.qos.logback.core.rolling;
+
+public interface NamingAndTriggeringPolicy<E> extends TriggeringPolicy<E> {
+
+ String getElapsedPeriodsFileName();
+}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.java Fri Jul 24 10:07:40 2009
@@ -17,10 +17,8 @@
import ch.qos.logback.core.rolling.helper.AsynchronousCompressor;
import ch.qos.logback.core.rolling.helper.CompressionMode;
import ch.qos.logback.core.rolling.helper.Compressor;
-import ch.qos.logback.core.rolling.helper.DateTokenConverter;
import ch.qos.logback.core.rolling.helper.FileNamePattern;
import ch.qos.logback.core.rolling.helper.RenameUtil;
-import ch.qos.logback.core.rolling.helper.RollingCalendar;
import ch.qos.logback.core.rolling.helper.TimeBasedCleaner;
/**
@@ -38,13 +36,6 @@
static final String FNP_NOT_SET = "The FileNamePattern option must be set before using TimeBasedRollingPolicy. ";
static final int NO_DELETE_HISTORY = 0;
- RollingCalendar rc;
- long currentTime;
- long nextCheck;
- // indicate whether the time has been forced or not
- boolean isTimeForced = false;
- Date lastCheck = null;
- String elapsedPeriodsFileName;
FileNamePattern activeFileNamePattern;
Compressor compressor;
RenameUtil renameUtil = new RenameUtil();
@@ -53,27 +44,32 @@
int maxHistory = NO_DELETE_HISTORY;
TimeBasedCleaner tbCleaner;
- public void setCurrentTime(long timeInMillis) {
- currentTime = timeInMillis;
- isTimeForced = true;
- }
-
- public long getCurrentTime() {
- // if time is forced return the time set by user
- if (isTimeForced) {
- return currentTime;
- } else {
- return System.currentTimeMillis();
- }
- }
+ DefaultTimeBasedTriggeringPolicy<E> timeBasedTriggering = new DefaultTimeBasedTriggeringPolicy<E>();
+
+// public void setCurrentTime(long timeInMillis) {
+// currentTime = timeInMillis;
+// isTimeForced = true;
+// }
+//
+// public long getCurrentTime() {
+// // if time is forced return the time set by user
+// if (isTimeForced) {
+// return currentTime;
+// } else {
+// return System.currentTimeMillis();
+// }
+// }
public void start() {
// set the LR for our utility object
renameUtil.setContext(this.context);
+ timeBasedTriggering.setContext(context);
+
// find out period from the filename pattern
if (fileNamePatternStr != null) {
fileNamePattern = new FileNamePattern(fileNamePatternStr, this.context);
+ timeBasedTriggering.fileNamePattern = fileNamePattern;
determineCompressionMode();
} else {
addWarn(FNP_NOT_SET);
@@ -82,14 +78,7 @@
+ CoreConstants.SEE_FNP_NOT_SET);
}
- DateTokenConverter dtc = fileNamePattern.getDateTokenConverter();
-
- if (dtc == null) {
- throw new IllegalStateException("FileNamePattern ["
- + fileNamePattern.getPattern()
- + "] does not contain a valid DateToken");
- }
-
+
compressor = new Compressor(compressionMode);
compressor.setContext(context);
@@ -107,51 +96,36 @@
case NONE:
activeFileNamePattern = fileNamePattern;
}
-
+
addInfo("Will use the pattern " + activeFileNamePattern
+ " for the active file");
- rc = new RollingCalendar();
- rc.init(dtc.getDatePattern());
- addInfo("The date pattern is '" + dtc.getDatePattern()
- + "' from file name pattern '" + fileNamePattern.getPattern() + "'.");
- rc.printPeriodicity(this);
-
- // lastCheck can be set by test classes
- // if it has not been set, we set it here
- if (lastCheck == null) {
- lastCheck = new Date();
- lastCheck.setTime(getCurrentTime());
- if (getParentsRawFileProperty() != null) {
- File currentFile = new File(getParentsRawFileProperty());
- if (currentFile.exists() && currentFile.canRead()) {
- lastCheck.setTime(currentFile.lastModified());
- }
- }
- }
- nextCheck = rc.getNextTriggeringMillis(lastCheck);
-
+ timeBasedTriggering.activeFileNamePattern = activeFileNamePattern;
+ timeBasedTriggering.start();
+
if (maxHistory != NO_DELETE_HISTORY) {
- tbCleaner = new TimeBasedCleaner(fileNamePattern, rc, maxHistory);
+ tbCleaner = new TimeBasedCleaner(fileNamePattern, timeBasedTriggering.rc, maxHistory);
}
}
- // allow Test classes to act on the lastCheck field to simulate old
- // log files needing rollover
- void setLastCheck(Date _lastCheck) {
- this.lastCheck = _lastCheck;
- }
- boolean rolloverTargetIsParentFile() {
- return (getParentsRawFileProperty() != null && getParentsRawFileProperty()
- .equals(elapsedPeriodsFileName));
+ public long getCurrentTime() {
+ return timeBasedTriggering.getCurrentTime();
}
-
+ public void setCurrentTime(long timeInMillis) {
+ timeBasedTriggering.setCurrentTime(timeInMillis);
+ }
+ void setLastCheck(Date _lastCheck) {
+ timeBasedTriggering.setLastCheck(_lastCheck);
+ }
+
public void rollover() throws RolloverFailure {
// when rollover is called the elapsed period's file has
// been already closed. This is a working assumption of this method.
+ String elapsedPeriodsFileName = timeBasedTriggering.getElapsedPeriodsFileName();
+
if (compressionMode == CompressionMode.NONE) {
if (getParentsRawFileProperty() != null) {
renameUtil.rename(getParentsRawFileProperty(), elapsedPeriodsFileName);
@@ -165,7 +139,7 @@
}
if (tbCleaner != null) {
- tbCleaner.clean(new Date(getCurrentTime()));
+ tbCleaner.clean(new Date(timeBasedTriggering.getCurrentTime()));
}
}
@@ -204,36 +178,35 @@
*
*/
public String getActiveFileName() {
- String parentsRawFileProperty = getParentsRawFileProperty();
-
- if (parentsRawFileProperty != null) {
- return parentsRawFileProperty;
- } else {
- return getLatestPeriodsFileName();
- }
+
+ return activeFileNamePattern.convertDate(timeBasedTriggering.lastCheck);
+
}
- // get the active file name for the current (latest) period
- private String getLatestPeriodsFileName() {
- return activeFileNamePattern.convertDate(lastCheck);
- }
+// // get the active file name for the current (latest) period
+// private String getLatestPeriodsFileName() {
+// return activeFileNamePattern.convertDate(lastCheck);
+// }
public boolean isTriggeringEvent(File activeFile, final E event) {
- long time = getCurrentTime();
-
- if (time >= nextCheck) {
- // We set the elapsedPeriodsFileName before we set the 'lastCheck'
- // variable
- // The elapsedPeriodsFileName corresponds to the file name of the period
- // that just elapsed.
- elapsedPeriodsFileName = activeFileNamePattern.convertDate(lastCheck);
-
- lastCheck.setTime(time);
- nextCheck = rc.getNextTriggeringMillis(lastCheck);
- return true;
- } else {
- return false;
- }
+
+ return timeBasedTriggering.isTriggeringEvent(activeFile, event);
+
+// long time = getCurrentTime();
+//
+// if (time >= nextCheck) {
+// // We set the elapsedPeriodsFileName before we set the 'lastCheck'
+// // variable
+// // The elapsedPeriodsFileName corresponds to the file name of the period
+// // that just elapsed.
+// elapsedPeriodsFileName = activeFileNamePattern.convertDate(lastCheck);
+//
+// lastCheck.setTime(time);
+// nextCheck = rc.getNextTriggeringMillis(lastCheck);
+// return true;
+// } else {
+// return false;
+// }
}
/**
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/RenamingTest.java Fri Jul 24 10:07:40 2009
@@ -54,7 +54,6 @@
RollingFileAppender<Object> rfa = new RollingFileAppender<Object>();
rfa.setLayout(layout);
rfa.setContext(context);
- rfa.setFile(CoreTestConstants.OUTPUT_DIR_PREFIX + "test.log");
// rollover by the second
String datePattern = "yyyy-MM-dd_HH_mm_ss";
@@ -64,7 +63,6 @@
TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
tbrp.setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX + "test-%d{"
+ datePattern + "}");
- // tbrp.setActiveFileName("src/test/output/test.log");
tbrp.setContext(context);
tbrp.setParent(rfa);
tbrp.start();
@@ -72,22 +70,24 @@
rfa.setRollingPolicy(tbrp);
rfa.start();
- // StatusPrinter.print(context.getStatusManager());
- Calendar cal = Calendar.getInstance();
+ Calendar cal0 = Calendar.getInstance();
rfa.doAppend("Hello 0");
+
DelayerUtil.delayUntilNextSecond(50);
+
+ Calendar cal1 = Calendar.getInstance();
rfa.doAppend("Hello 1");
filenames[0] = CoreTestConstants.OUTPUT_DIR_PREFIX + "test-"
- + sdf.format(cal.getTime());
- filenames[1] = CoreTestConstants.OUTPUT_DIR_PREFIX + "test.log";
-
+ + sdf.format(cal0.getTime());
+ filenames[1] = CoreTestConstants.OUTPUT_DIR_PREFIX + "test-"
+ + sdf.format(cal1.getTime());
+
+
for (int i = 0; i < filenames.length; i++) {
- // System.out.println("before i=" + i);
assertTrue(Compare.compare(filenames[i], CoreTestConstants.TEST_DIR_PREFIX
+ "witness/rolling/renaming." + i));
- // System.out.println("post i=" + i);
}
}
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java Fri Jul 24 10:07:40 2009
@@ -42,8 +42,8 @@
* <pre>
* Compression file option Stop/Restart
* Test1 NO BLANK NO
- * Test2 NO BLANK YES
- * Test3 YES BLANK NO
+ * Test2 YES BLANK NO
+ * Test3 NO BLANK YES
* Test4 NO SET YES
* Test5 NO SET NO
* Test6 YES SET NO
@@ -148,55 +148,11 @@
}
/**
- * No compression, file option left blank, with stop/restart,
- */
- @Test
- public void noCompression_FileBlank_StopRestart_2() throws Exception {
- String testId = "test2";
-
- initRFA(rfa1, null);
- initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
- + DATE_PATTERN + "}", currentTime, 0);
-
- // a new file is created by virtue of rfa.start();
- addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
-
- incCurrentTime(1100);
- tbrp1.setCurrentTime(currentTime);
-
- for (int i = 0; i <= 2; i++) {
- rfa1.doAppend("Hello---" + i);
- addExpectedFileNamedIfItsTime_ByDate(testId, false);
- incCurrentTime(500);
- tbrp1.setCurrentTime(currentTime);
- }
-
- rfa1.stop();
-
- initRFA(rfa2, null);
- initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
- + DATE_PATTERN + "}", tbrp1.getCurrentTime(), 0);
-
- for (int i = 0; i <= 2; i++) {
- addExpectedFileNamedIfItsTime_ByDate(testId, false);
- rfa2.doAppend("World---" + i);
- incCurrentTime(100);
- tbrp2.setCurrentTime(currentTime);
- }
-
- int i = 0;
- for (String fn : expectedFilenameList) {
- assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/tbr-" + testId + "." + i++));
- }
- }
-
- /**
* With compression, file option left blank, no stop/restart
*/
@Test
- public void withCompression_FileBlank_NoRestart_3() throws Exception {
- String testId = "test3";
+ public void withCompression_FileBlank_NoRestart_2() throws Exception {
+ String testId = "test2";
initRFA(rfa1, null);
initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+ DATE_PATTERN + "}.gz", currentTime, 0);
@@ -224,15 +180,17 @@
}
/**
- * Without compression, file option set, with stop/restart
+ * No compression, file option left blank, with stop/restart,
*/
@Test
- public void noCompression_FileSet_StopRestart_4() throws Exception {
- String testId = "test4";
- initRFA(rfa1, testId2FileName(testId));
+ public void noCompression_FileBlank_StopRestart_3() throws Exception {
+ String testId = "test3";
+
+ initRFA(rfa1, null);
initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+ DATE_PATTERN + "}", currentTime, 0);
+ // a new file is created by virtue of rfa.start();
addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
incCurrentTime(1100);
@@ -247,140 +205,182 @@
rfa1.stop();
- initRFA(rfa2, testId2FileName(testId));
+ initRFA(rfa2, null);
initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
- + DATE_PATTERN + "}", currentTime, currentTime);
-
- for (int i = 0; i <= 2; i++) {
- rfa2.doAppend("World---" + i);
- addExpectedFileNamedIfItsTime_ByDate(testId, false);
- incCurrentTime(100);
- tbrp2.setCurrentTime(currentTime);
- }
-
- massageExpectedFilesToCorresponToCurrentTarget("test4.log");
-
- int i = 0;
- for (String fn : expectedFilenameList) {
- assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/tbr-" + testId + "." + i++));
- }
- }
-
- @Test
- public void noCompression_FileSet_StopRestart_WithLongWait_4B()
- throws Exception {
- String testId = "test4B";
- initRFA(rfa1, testId2FileName(testId));
- initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
- + DATE_PATTERN + "}", currentTime, 0);
-
- addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
-
- incCurrentTime(1100);
- tbrp1.setCurrentTime(currentTime);
+ + DATE_PATTERN + "}", tbrp1.getCurrentTime(), 0);
for (int i = 0; i <= 2; i++) {
- rfa1.doAppend("Hello---" + i);
addExpectedFileNamedIfItsTime_ByDate(testId, false);
- incCurrentTime(500);
- tbrp1.setCurrentTime(currentTime);
- }
-
- rfa1.stop();
-
- long fileTimestamp = currentTime;
- incCurrentTime(2000);
-
- initRFA(rfa2, CoreTestConstants.OUTPUT_DIR_PREFIX + "test4B.log");
- initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId +"-%d{"
- + DATE_PATTERN + "}", currentTime, fileTimestamp);
-
- for (int i = 0; i <= 2; i++) {
rfa2.doAppend("World---" + i);
- addExpectedFileNamedIfItsTime_ByDate(testId, false);
incCurrentTime(100);
tbrp2.setCurrentTime(currentTime);
}
- massageExpectedFilesToCorresponToCurrentTarget("test4B.log");
-
- int i = 0;
- for (String fn : expectedFilenameList) {
- assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/tbr-test4B." + i++));
- }
-
- }
-
- /**
- * No compression, file option set, without stop/restart
- */
- @Test
- public void noCompression_FileSet_NoRestart_5() throws Exception {
- String testId = "test5";
-
- initRFA(rfa1, testId2FileName(testId));
- initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
- + DATE_PATTERN + "}", currentTime, 0);
-
- addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
-
- incCurrentTime(1100);
- tbrp1.setCurrentTime(currentTime);
-
- for (int i = 0; i < 3; i++) {
- rfa1.doAppend("Hello---" + i);
- addExpectedFileNamedIfItsTime_ByDate(testId, false);
- incCurrentTime(500);
- tbrp1.setCurrentTime(currentTime);
- }
-
- massageExpectedFilesToCorresponToCurrentTarget("test5.log");
-
- int i = 0;
- for (String fn : expectedFilenameList) {
- assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/tbr-test5." + i++));
- }
- }
-
- /**
- * With compression, file option set, no stop/restart,
- */
- @Test
- public void withCompression_FileSet_NoRestart_6() throws Exception {
-
- String testId = "test6";
-
- initRFA(rfa1, testId2FileName(testId));
- initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
- + DATE_PATTERN + "}.gz", currentTime, 0);
-
- addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), true);
-
- incCurrentTime(1100);
- tbrp1.setCurrentTime(currentTime);
-
- for (int i = 0; i < 3; i++) {
- rfa1.doAppend("Hello---" + i);
- addExpectedFileNamedIfItsTime_ByDate(testId, true);
- incCurrentTime(500);
- tbrp1.setCurrentTime(currentTime);
- }
-
- // wait for the compression task to finish
- tbrp1.future.get(1000, TimeUnit.MILLISECONDS);
-
- massageExpectedFilesToCorresponToCurrentTarget("test6.log");
-
int i = 0;
for (String fn : expectedFilenameList) {
assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
- + "witness/rolling/tbr-" + testId + "." + i + addGZIfNotLast(i)));
- i++;
+ + "witness/rolling/tbr-" + testId + "." + i++));
}
}
+//
+// /**
+// * Without compression, file option set, with stop/restart
+// */
+// @Test
+// public void noCompression_FileSet_StopRestart_4() throws Exception {
+// String testId = "test4";
+// initRFA(rfa1, testId2FileName(testId));
+// initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+// + DATE_PATTERN + "}", currentTime, 0);
+//
+// addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
+//
+// incCurrentTime(1100);
+// tbrp1.setCurrentTime(currentTime);
+//
+// for (int i = 0; i <= 2; i++) {
+// rfa1.doAppend("Hello---" + i);
+// addExpectedFileNamedIfItsTime_ByDate(testId, false);
+// incCurrentTime(500);
+// tbrp1.setCurrentTime(currentTime);
+// }
+//
+// rfa1.stop();
+//
+// initRFA(rfa2, testId2FileName(testId));
+// initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+// + DATE_PATTERN + "}", currentTime, currentTime);
+//
+// for (int i = 0; i <= 2; i++) {
+// rfa2.doAppend("World---" + i);
+// addExpectedFileNamedIfItsTime_ByDate(testId, false);
+// incCurrentTime(100);
+// tbrp2.setCurrentTime(currentTime);
+// }
+//
+// massageExpectedFilesToCorresponToCurrentTarget("test4.log");
+//
+// int i = 0;
+// for (String fn : expectedFilenameList) {
+// assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+// + "witness/rolling/tbr-" + testId + "." + i++));
+// }
+// }
+//
+// @Test
+// public void noCompression_FileSet_StopRestart_WithLongWait_4B()
+// throws Exception {
+// String testId = "test4B";
+// initRFA(rfa1, testId2FileName(testId));
+// initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+// + DATE_PATTERN + "}", currentTime, 0);
+//
+// addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
+//
+// incCurrentTime(1100);
+// tbrp1.setCurrentTime(currentTime);
+//
+// for (int i = 0; i <= 2; i++) {
+// rfa1.doAppend("Hello---" + i);
+// addExpectedFileNamedIfItsTime_ByDate(testId, false);
+// incCurrentTime(500);
+// tbrp1.setCurrentTime(currentTime);
+// }
+//
+// rfa1.stop();
+//
+// long fileTimestamp = currentTime;
+// incCurrentTime(2000);
+//
+// initRFA(rfa2, CoreTestConstants.OUTPUT_DIR_PREFIX + "test4B.log");
+// initTRBP(rfa2, tbrp2, CoreTestConstants.OUTPUT_DIR_PREFIX + testId +"-%d{"
+// + DATE_PATTERN + "}", currentTime, fileTimestamp);
+//
+// for (int i = 0; i <= 2; i++) {
+// rfa2.doAppend("World---" + i);
+// addExpectedFileNamedIfItsTime_ByDate(testId, false);
+// incCurrentTime(100);
+// tbrp2.setCurrentTime(currentTime);
+// }
+//
+// massageExpectedFilesToCorresponToCurrentTarget("test4B.log");
+//
+// int i = 0;
+// for (String fn : expectedFilenameList) {
+// assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+// + "witness/rolling/tbr-test4B." + i++));
+// }
+//
+// }
+//
+// /**
+// * No compression, file option set, without stop/restart
+// */
+// @Test
+// public void noCompression_FileSet_NoRestart_5() throws Exception {
+// String testId = "test5";
+//
+// initRFA(rfa1, testId2FileName(testId));
+// initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+// + DATE_PATTERN + "}", currentTime, 0);
+//
+// addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), false);
+//
+// incCurrentTime(1100);
+// tbrp1.setCurrentTime(currentTime);
+//
+// for (int i = 0; i < 3; i++) {
+// rfa1.doAppend("Hello---" + i);
+// addExpectedFileNamedIfItsTime_ByDate(testId, false);
+// incCurrentTime(500);
+// tbrp1.setCurrentTime(currentTime);
+// }
+//
+// massageExpectedFilesToCorresponToCurrentTarget("test5.log");
+//
+// int i = 0;
+// for (String fn : expectedFilenameList) {
+// assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+// + "witness/rolling/tbr-test5." + i++));
+// }
+// }
+//
+// /**
+// * With compression, file option set, no stop/restart,
+// */
+// @Test
+// public void withCompression_FileSet_NoRestart_6() throws Exception {
+//
+// String testId = "test6";
+//
+// initRFA(rfa1, testId2FileName(testId));
+// initTRBP(rfa1, tbrp1, CoreTestConstants.OUTPUT_DIR_PREFIX + testId + "-%d{"
+// + DATE_PATTERN + "}.gz", currentTime, 0);
+//
+// addExpectedFileName_ByDate(testId, getDateOfCurrentPeriodsStart(), true);
+//
+// incCurrentTime(1100);
+// tbrp1.setCurrentTime(currentTime);
+//
+// for (int i = 0; i < 3; i++) {
+// rfa1.doAppend("Hello---" + i);
+// addExpectedFileNamedIfItsTime_ByDate(testId, true);
+// incCurrentTime(500);
+// tbrp1.setCurrentTime(currentTime);
+// }
+//
+// // wait for the compression task to finish
+// tbrp1.future.get(1000, TimeUnit.MILLISECONDS);
+//
+// massageExpectedFilesToCorresponToCurrentTarget("test6.log");
+//
+// int i = 0;
+// for (String fn : expectedFilenameList) {
+// assertTrue(Compare.compare(fn, CoreTestConstants.TEST_DIR_PREFIX
+// + "witness/rolling/tbr-" + testId + "." + i + addGZIfNotLast(i)));
+// i++;
+// }
+// }
// =========================================================================
// utility methods
Added: logback/trunk/logback-core/src/test/witness/rolling/tbr-test2.0.gz
==============================================================================
Binary file. No diff available.
Added: logback/trunk/logback-core/src/test/witness/rolling/tbr-test2.1.gz
==============================================================================
Binary file. No diff available.
Added: logback/trunk/logback-core/src/test/witness/rolling/tbr-test2.2
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/witness/rolling/tbr-test2.2 Fri Jul 24 10:07:40 2009
@@ -0,0 +1 @@
+Hello---2
1
0

23 Jul '09
Author: ceki
Date: Thu Jul 23 22:47:55 2009
New Revision: 2375
Modified:
logback/trunk/logback-site/src/site/pages/news.html
Log:
- blurb about append mode being mandatory
Modified: logback/trunk/logback-site/src/site/pages/news.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/news.html (original)
+++ logback/trunk/logback-site/src/site/pages/news.html Thu Jul 23 22:47:55 2009
@@ -38,6 +38,11 @@
reported by Roland Klein and independently by Didier Besset.
</p>
+ <p>Append mode is now mandatory in
+ <code>RollingFileAppender</code>. This was already the default and
+ truncation mode is unreasonable in most cases. For example, in
+ truncate mode when an application stops and is quickly re-started,
+ any pre-existing log file for the current period will be lost.</p>
<hr width="80%" align="center" />
1
0

svn commit: r2374 - logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling
by noreply.ceki@qos.ch 23 Jul '09
by noreply.ceki@qos.ch 23 Jul '09
23 Jul '09
Author: ceki
Date: Thu Jul 23 22:43:55 2009
New Revision: 2374
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java
Log:
make append mode mandatory for RollingFileAppender
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingFileAppender.java Thu Jul 23 22:43:55 2009
@@ -45,7 +45,13 @@
addWarn("For more information, please visit http://logback.qos.ch/codes.html#rfa_no_tp");
return;
}
-
+
+ // we don't want to void existing log files
+ if(!append) {
+ addWarn("Append mode is mandatory for RollingFileAppender");
+ append = true;
+ }
+
if (rollingPolicy == null) {
addError("No RollingPolicy was set for the RollingFileAppender named "
+ getName());
1
0