Skip to content

Commit

Permalink
make totalSizeCap argument of type FileSize
Browse files Browse the repository at this point in the history
  • Loading branch information
ceki committed Mar 29, 2016
1 parent 412fd07 commit 56b7785
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 13 deletions.
Expand Up @@ -427,4 +427,12 @@ public void packageDataEnabledByConfigAttribute() throws JoranException {
configure(configFileAsStr);
assertTrue(loggerContext.isPackagingDataEnabled());
}


@Test
public void valueOfConvetion() throws JoranException {
String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX + "valueOfConvention.xml";
configure(configFileAsStr);
checker.assertIsWarningOrErrorFree();
}
}
Expand Up @@ -96,6 +96,8 @@ public void body(InterpretationContext ec, String body) {
break;
case AS_BASIC_PROPERTY_COLLECTION:
actionData.parentBean.addBasicProperty(actionData.propertyName, finalBody);
default:
addError("Unexpected aggregationType " + actionData.aggregationType);
}
}

Expand Down
Expand Up @@ -46,10 +46,11 @@ public class NestedComplexPropertyIA extends ImplicitAction {
// be followed by a corresponding pop.
Stack<IADataForComplexProperty> actionDataStack = new Stack<IADataForComplexProperty>();

private final BeanDescriptionCache beanDescriptionCache;
public NestedComplexPropertyIA(BeanDescriptionCache beanDescriptionCache) {
this.beanDescriptionCache=beanDescriptionCache;
}
private final BeanDescriptionCache beanDescriptionCache;

public NestedComplexPropertyIA(BeanDescriptionCache beanDescriptionCache) {
this.beanDescriptionCache = beanDescriptionCache;
}

public boolean isApplicable(ElementPath elementPath, Attributes attributes, InterpretationContext ic) {

Expand All @@ -61,7 +62,7 @@ public boolean isApplicable(ElementPath elementPath, Attributes attributes, Inte
}

Object o = ic.peekObject();
PropertySetter parentBean = new PropertySetter(beanDescriptionCache,o);
PropertySetter parentBean = new PropertySetter(beanDescriptionCache, o);
parentBean.setContext(context);

AggregationType aggregationType = parentBean.computeAggregationType(nestedElementTagName);
Expand Down Expand Up @@ -145,7 +146,7 @@ public void end(InterpretationContext ec, String tagName) {
return;
}

PropertySetter nestedBean = new PropertySetter(beanDescriptionCache,actionData.getNestedComplexProperty());
PropertySetter nestedBean = new PropertySetter(beanDescriptionCache, actionData.getNestedComplexProperty());
nestedBean.setContext(context);

// have the nested element point to its parent if possible
Expand Down Expand Up @@ -174,8 +175,9 @@ public void end(InterpretationContext ec, String tagName) {
break;
case AS_COMPLEX_PROPERTY_COLLECTION:
actionData.parentBean.addComplexProperty(tagName, actionData.getNestedComplexProperty());

break;
default:
addError("Unexpected aggregationType " + actionData.aggregationType);
}
}
}
Expand Down
Expand Up @@ -29,6 +29,7 @@
import ch.qos.logback.core.rolling.helper.FileFilterUtil;
import ch.qos.logback.core.rolling.helper.FileNamePattern;
import ch.qos.logback.core.rolling.helper.RenameUtil;
import ch.qos.logback.core.util.FileSize;

/**
* <code>TimeBasedRollingPolicy</code> is both easy to configure and quite
Expand All @@ -51,7 +52,7 @@ public class TimeBasedRollingPolicy<E> extends RollingPolicyBase implements Trig
Future<?> cleanUpFuture;

private int maxHistory = UNBOUND_HISTORY;
private long totalSizeCap = UNBOUND_TOTAL_SIZE;
private FileSize totalSizeCap = new FileSize(UNBOUND_TOTAL_SIZE);

private ArchiveRemover archiveRemover;

Expand Down Expand Up @@ -104,13 +105,13 @@ public void start() {
if (maxHistory != UNBOUND_HISTORY) {
archiveRemover = timeBasedFileNamingAndTriggeringPolicy.getArchiveRemover();
archiveRemover.setMaxHistory(maxHistory);
archiveRemover.setTotalSizeCap(totalSizeCap);
archiveRemover.setTotalSizeCap(totalSizeCap.getSize());
if (cleanHistoryOnStart) {
addInfo("Cleaning on start up");
Date now = new Date(timeBasedFileNamingAndTriggeringPolicy.getCurrentTime());
cleanUpFuture = archiveRemover.cleanAsynchronously(now);
}
} else if (totalSizeCap != UNBOUND_TOTAL_SIZE) {
} else if (totalSizeCap.getSize() != UNBOUND_TOTAL_SIZE) {
addWarn("'maxHistory' is not set, ignoring 'totalSizeCap' option with value ["+totalSizeCap+"]");
}

Expand Down Expand Up @@ -255,8 +256,7 @@ public String toString() {
return "c.q.l.core.rolling.TimeBasedRollingPolicy@"+this.hashCode();
}

public void setTotalSizeCap(long totalSizeCap) {
public void setTotalSizeCap(FileSize totalSizeCap) {
this.totalSizeCap = totalSizeCap;

}
}
Expand Up @@ -103,6 +103,10 @@ public boolean isErrorFree(long threshold) {
return Status.ERROR > getHighestLevel(threshold);
}

public boolean isWarningOrErrorFree(long threshold) {
return Status.WARN > getHighestLevel(threshold);
}

public boolean containsMatch(long threshold, int level, String regex) {
List<Status> filteredList = filterStatusListByTimeThreshold(sm.getCopyOfStatusList(), threshold);
Pattern p = Pattern.compile(regex);
Expand Down
Expand Up @@ -41,6 +41,7 @@
import ch.qos.logback.core.pattern.SpacePadder;
import ch.qos.logback.core.rolling.helper.RollingCalendar;
import ch.qos.logback.core.status.StatusChecker;
import ch.qos.logback.core.util.FileSize;
import ch.qos.logback.core.util.FixedRateInvocationGate;
import ch.qos.logback.core.util.StatusPrinter;

Expand Down Expand Up @@ -411,7 +412,7 @@ void buildRollingFileAppender(ConfigParameters cp, boolean cleanHistoryOnStart)
tbrp.setContext(context);
tbrp.setFileNamePattern(cp.fileNamePattern);
tbrp.setMaxHistory(cp.maxHistory);
tbrp.setTotalSizeCap(cp.sizeCap);
tbrp.setTotalSizeCap(new FileSize(cp.sizeCap));
tbrp.setParent(rfa);
tbrp.setCleanHistoryOnStart(cleanHistoryOnStart);
tbrp.timeBasedFileNamingAndTriggeringPolicy = tbfnatp;
Expand Down
Expand Up @@ -51,4 +51,7 @@ public void assertIsErrorFree() {
assertTrue(isErrorFree(0));
}

public void assertIsWarningOrErrorFree() {
assertTrue(isWarningOrErrorFree(0));
}
}

0 comments on commit 56b7785

Please sign in to comment.