Search in sources :

Example 1 with IntegerTokenConverter

use of ch.qos.logback.core.rolling.helper.IntegerTokenConverter in project cdap by caskdata.

the class FixedWindowRollingPolicy method start.

@Override
public void start() {
    if (fileNamePatternStr != null) {
        if (context instanceof AppenderContext) {
            AppenderContext context = (AppenderContext) this.context;
            fileNamePatternStr = fileNamePatternStr.replace("instanceId", Integer.toString(context.getInstanceId()));
        } else if (!Boolean.TRUE.equals(context.getObject(Constants.Logging.PIPELINE_VALIDATION))) {
            throw new IllegalStateException("Expected logger context instance of " + AppenderContext.class.getName() + " but got " + context.getClass().getName());
        }
        fileNamePattern = new FileNamePattern(fileNamePatternStr, this.context);
    } else {
        LOG.error(FNP_NOT_SET);
        throw new IllegalStateException(FNP_NOT_SET + CoreConstants.SEE_FNP_NOT_SET);
    }
    if (maxIndex < minIndex) {
        LOG.warn("MaxIndex {} cannot be smaller than MinIndex {}.", maxIndex, minIndex);
        maxIndex = minIndex;
    }
    if ((maxIndex - minIndex) > MAX_WINDOW_SIZE) {
        LOG.warn("Large window sizes are not allowed.");
        maxIndex = minIndex + MAX_WINDOW_SIZE;
        LOG.warn("MaxIndex reduced to " + maxIndex);
    }
    IntegerTokenConverter itc = fileNamePattern.getIntegerTokenConverter();
    if (itc == null) {
        throw new IllegalStateException("FileNamePattern [" + fileNamePattern.getPattern() + "] does not contain a valid IntegerToken");
    }
    processedIndex = maxIndex;
    super.start();
}
Also used : FileNamePattern(ch.qos.logback.core.rolling.helper.FileNamePattern) IntegerTokenConverter(ch.qos.logback.core.rolling.helper.IntegerTokenConverter) AppenderContext(co.cask.cdap.api.logging.AppenderContext)

Aggregations

FileNamePattern (ch.qos.logback.core.rolling.helper.FileNamePattern)1 IntegerTokenConverter (ch.qos.logback.core.rolling.helper.IntegerTokenConverter)1 AppenderContext (co.cask.cdap.api.logging.AppenderContext)1