ch.qos.logback.core.util.FileSize.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(13.7k)|赞(0)|评价(0)|浏览(177)

本文整理了Java中ch.qos.logback.core.util.FileSize.<init>()方法的一些代码示例,展示了FileSize.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileSize.<init>()方法的具体详情如下:
包路径:ch.qos.logback.core.util.FileSize
类名称:FileSize
方法名:<init>

FileSize.<init>介绍

暂无

代码示例

代码示例来源:origin: jmxtrans/jmxtrans

/**
 * Initializes the logger. This is called when we need to create a new
 * logger for the given file name.
 *
 * @param fileStr
 * @return a new Logger instance for the given fileStr
 * @throws IOException
 */
protected Logger initLogger(String fileStr) throws IOException {
  String loggerName = "NagiosWriter" + this.hashCode();
  final PatternLayoutEncoder encoder = new PatternLayoutEncoder();
  encoder.setContext(loggerContext);
  encoder.setPattern(LOG_PATTERN);
  encoder.start();
  final FileAppender appender = new FileAppender();
  appender.setContext(loggerContext);
  appender.setName(loggerName + "File");
  appender.setAppend(true);
  appender.setBufferSize(new FileSize(LOG_IO_BUFFER_SIZE_BYTES));
  appender.setFile(fileStr);
  appender.setEncoder(encoder);
  appender.start();
  Logger logger = loggerContext.getLogger(loggerName);
  logger.addAppender(appender);
  logger.setLevel(Level.INFO);
  logger.setAdditive(false);
  return logger;
}

代码示例来源:origin: dropwizard/dropwizard

appender.setContext(context);
  appender.setFile(currentLogFilename);
  appender.setBufferSize(new FileSize(bufferSize.toBytes()));
    triggeringPolicy.setMaxFileSize(new FileSize(maxFileSize.toBytes()));
    triggeringPolicy.setContext(context);
    triggeringPolicy.start();
      sizeAndTimeBasedRollingPolicy.setMaxFileSize(new FileSize(maxFileSize.toBytes()));
      rollingPolicy = sizeAndTimeBasedRollingPolicy;
      rollingPolicy.setTotalSizeCap(new FileSize(totalSizeCap.toBytes()));
appender.setContext(context);
appender.setFile(currentLogFilename);
appender.setBufferSize(new FileSize(bufferSize.toBytes()));
return appender;

代码示例来源:origin: jmxtrans/jmxtrans

protected Appender buildAppender(String loggerName, String fileStr) {
  final RollingFileAppender appender = new RollingFileAppender();
  appender.setName(loggerName + "RollingFile");
  appender.setContext(loggerContext);
  appender.setImmediateFlush(true);
  appender.setBufferSize(new FileSize(LOG_IO_BUFFER_SIZE_BYTES));
  appender.setFile(fileStr);
  appender.setEncoder(buildEncoder());
  TriggeringPolicy triggeringPolicy = buildTriggeringPolicy();
  if (triggeringPolicy != null) {
    appender.setTriggeringPolicy(triggeringPolicy);
  }
  appender.setRollingPolicy(buildRollingPolicy(appender, fileStr));
  appender.start();
  return appender;
}

代码示例来源:origin: camunda/camunda-bpm-platform

static public FileSize valueOf(String fileSizeStr) {
  Matcher matcher = FILE_SIZE_PATTERN.matcher(fileSizeStr);

  long coefficient;
  if (matcher.matches()) {
   String lenStr = matcher.group(DOUBLE_GROUP);
   String unitStr = matcher.group(UNIT_GROUP);

   long lenValue = Long.valueOf(lenStr);
   if (unitStr.equalsIgnoreCase("")) {
    coefficient = 1;
   } else if (unitStr.equalsIgnoreCase("kb")) {
    coefficient = KB_COEFFICIENT;
   } else if (unitStr.equalsIgnoreCase("mb")) {
    coefficient = MB_COEFFICIENT;
   } else if (unitStr.equalsIgnoreCase("gb")) {
    coefficient = GB_COEFFICIENT;
   } else {
    throw new IllegalStateException("Unexpected " + unitStr);
   }
   return new FileSize(lenValue * coefficient);
  } else {
   throw new IllegalArgumentException("String value [" + fileSizeStr
     + "] is not in the expected format.");
  }

 }
}

代码示例来源:origin: org.jmxtrans/jmxtrans-output-log4j

private FileSize toFileSize(String s) {
  return new FileSize(parseLong(s));
}

代码示例来源:origin: Nextdoor/bender

static public FileSize valueOf(String fileSizeStr) {
  Matcher matcher = FILE_SIZE_PATTERN.matcher(fileSizeStr);
  long coefficient;
  if (matcher.matches()) {
    String lenStr = matcher.group(DOUBLE_GROUP);
    String unitStr = matcher.group(UNIT_GROUP);
    long lenValue = Long.valueOf(lenStr);
    if (unitStr.equalsIgnoreCase("")) {
      coefficient = 1;
    } else if (unitStr.equalsIgnoreCase("kb")) {
      coefficient = KB_COEFFICIENT;
    } else if (unitStr.equalsIgnoreCase("mb")) {
      coefficient = MB_COEFFICIENT;
    } else if (unitStr.equalsIgnoreCase("gb")) {
      coefficient = GB_COEFFICIENT;
    } else {
      throw new IllegalStateException("Unexpected " + unitStr);
    }
    return new FileSize(lenValue * coefficient);
  } else {
    throw new IllegalArgumentException("String value [" + fileSizeStr + "] is not in the expected format.");
  }
}

代码示例来源:origin: tony19/logback-android

static public FileSize valueOf(String fileSizeStr) {
 Matcher matcher = FILE_SIZE_PATTERN.matcher(fileSizeStr);
 long coefficient;
 if (matcher.matches()) {
  String lenStr = matcher.group(DOUBLE_GROUP);
  String unitStr = matcher.group(UNIT_GROUP);
  long lenValue = Long.valueOf(lenStr);
  if (unitStr.equalsIgnoreCase("")) {
   coefficient = 1;
  } else if (unitStr.equalsIgnoreCase("kb")) {
   coefficient = KB_COEFFICIENT;
  } else if (unitStr.equalsIgnoreCase("mb")) {
   coefficient = MB_COEFFICIENT;
  } else if (unitStr.equalsIgnoreCase("gb")) {
   coefficient = GB_COEFFICIENT;
  } else {
   throw new IllegalStateException("Unexpected " + unitStr);
  }
  return new FileSize(lenValue * coefficient);
 } else {
  throw new IllegalArgumentException("String value [" + fileSizeStr
    + "] is not in the expected format.");
 }
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

static public FileSize valueOf(String fileSizeStr) {
  Matcher matcher = FILE_SIZE_PATTERN.matcher(fileSizeStr);
  long coefficient;
  if (matcher.matches()) {
    String lenStr = matcher.group(DOUBLE_GROUP);
    String unitStr = matcher.group(UNIT_GROUP);
    long lenValue = Long.valueOf(lenStr);
    if (unitStr.equalsIgnoreCase("")) {
      coefficient = 1;
    } else if (unitStr.equalsIgnoreCase("kb")) {
      coefficient = KB_COEFFICIENT;
    } else if (unitStr.equalsIgnoreCase("mb")) {
      coefficient = MB_COEFFICIENT;
    } else if (unitStr.equalsIgnoreCase("gb")) {
      coefficient = GB_COEFFICIENT;
    } else {
      throw new IllegalStateException("Unexpected " + unitStr);
    }
    return new FileSize(lenValue * coefficient);
  } else {
    throw new IllegalArgumentException("String value [" + fileSizeStr + "] is not in the expected format.");
  }
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

void capTotalSize(Date now) {
  long totalSize = 0;
  long totalRemoved = 0;
  for (int offset = 0; offset < maxHistory; offset++) {
    Date date = rc.getEndOfNextNthPeriod(now, -offset);
    File[] matchingFileArray = getFilesInPeriod(date);
    descendingSortByLastModified(matchingFileArray);
    for (File f : matchingFileArray) {
      long size = f.length();
      if (totalSize + size > totalSizeCap) {
        addInfo("Deleting [" + f + "]" + " of size " + new FileSize(size));
        totalRemoved += size;
        f.delete();
      }
      totalSize += size;
    }
  }
  addInfo("Removed  " + new FileSize(totalRemoved) + " of files");
}

代码示例来源:origin: Nextdoor/bender

void capTotalSize(Date now) {
  long totalSize = 0;
  long totalRemoved = 0;
  for (int offset = 0; offset < maxHistory; offset++) {
    Date date = rc.getEndOfNextNthPeriod(now, -offset);
    File[] matchingFileArray = getFilesInPeriod(date);
    descendingSortByLastModified(matchingFileArray);
    for (File f : matchingFileArray) {
      long size = f.length();
      if (totalSize + size > totalSizeCap) {
        addInfo("Deleting [" + f + "]" + " of size " + new FileSize(size));
        totalRemoved += size;
        f.delete();
      }
      totalSize += size;
    }
  }
  addInfo("Removed  " + new FileSize(totalRemoved) + " of files");
}

代码示例来源:origin: tony19/logback-android

private void capTotalSize(List<String> filenames) {
 long totalSize = 0;
 long totalRemoved = 0;
 String[] fnames = filenames.toArray(new String[0]);
 this.fileSorter.sort(fnames);
 for (String name : fnames) {
  File f = new File(name);
  long size = this.fileProvider.length(f);
  if (totalSize + size > this.totalSizeCap) {
   addInfo("Deleting [" + f + "]" + " of size " + new FileSize(size));
   if (!delete(f)) {
    size = 0;
   }
   totalRemoved += size;
  }
  totalSize += size;
 }
 addInfo("Removed  "+ new FileSize(totalRemoved) + " of files");
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

void capTotalSize(Date now) {
  long totalSize = 0;
  long totalRemoved = 0;
  for (int offset = 0; offset < maxHistory; offset++) {
    Date date = rc.getEndOfNextNthPeriod(now, -offset);
    File[] matchingFileArray = getFilesInPeriod(date);
    descendingSortByLastModified(matchingFileArray);
    for (File f : matchingFileArray) {
      long size = f.length();
      if (totalSize + size > totalSizeCap) {
        addInfo("Deleting [" + f + "]" + " of size " + new FileSize(size));
        totalRemoved += size;
        f.delete();
      }
      totalSize += size;
    }
  }
  addInfo("Removed  " + new FileSize(totalRemoved) + " of files");
}

代码示例来源:origin: tony19/logback-android

@Test
public void testToString() {
 {
  FileSize fs = new FileSize(8);
  assertEquals("8 Bytes", fs.toString());
 }
 {
  FileSize fs = new FileSize(8 * 1024 + 3);
  assertEquals("8 KB", fs.toString());
 }
 {
  FileSize fs = new FileSize(8 * 1024 * 1024 + 3 * 1024);
  assertEquals("8 MB", fs.toString());
 }
 {
  FileSize fs = new FileSize(8*1024*1024*1024L);
  assertEquals("8 GB", fs.toString());
 }
}

代码示例来源:origin: tony19/logback-android

@Test
public void dailyChronologSizeBasedRollover() {
 SizeAndTimeBasedFNATP<Object> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<Object>();
 sizeAndTimeBasedFNATP.setMaxFileSize(new FileSize(10000));
 sizeAndTimeBasedFNATP.invocationGate = fixedRateInvocationGate;
 tbfnatp = sizeAndTimeBasedFNATP;
 final String fileNamePattern = randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + ", GMT}/clean.%i.zip";
 cp.maxHistory(5).fileNamePattern(fileNamePattern).simulatedNumberOfPeriods(5 * 3);
 logOverMultiplePeriods(cp);
 final String[] dirNames = new String[] {
  "2018-07-21",
  "2018-07-22",
  "2018-07-23",
  "2018-07-24",
  "2018-07-25",
  "2018-07-26"
 };
 final File ROOT_DIR = new File(randomOutputDir);
 assertThat(Arrays.asList(ROOT_DIR.list()), containsInAnyOrder(dirNames));
 // the last dir contains the active file
 List<String> dirs = Arrays.asList(dirNames).subList(0, dirNames.length - 1);
 for (String dir : dirs) {
  assertThat(Arrays.asList(new File(ROOT_DIR, dir).list()), containsInAnyOrder("clean.0.zip", "clean.1.zip"));
 }
 assertThat(Arrays.asList(new File(ROOT_DIR, "2018-07-26").list()), contains("clean.0"));
}

代码示例来源:origin: tony19/logback-android

@Test
public void dailySizeBasedRolloverWithoutCap() {
 SizeAndTimeBasedFNATP<Object> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<Object>();
 sizeAndTimeBasedFNATP.invocationGate = fixedRateInvocationGate;
 sizeAndTimeBasedFNATP.setMaxFileSize(new FileSize(10000));
 tbfnatp = sizeAndTimeBasedFNATP;
 final String fileNamePattern = randomOutputDir + "/%d{" + DAILY_DATE_PATTERN + ", GMT}-clean.%i.zip";
 cp.maxHistory(5).fileNamePattern(fileNamePattern).simulatedNumberOfPeriods(5 * 4);
 logOverMultiplePeriods(cp);
 final File ROOT_DIR = new File(randomOutputDir);
 assertThat(Arrays.asList(ROOT_DIR.list()), containsInAnyOrder(
  "2018-07-26-clean.0.zip",
  "2018-07-26-clean.1.zip",
  "2018-07-27-clean.0.zip",
  "2018-07-27-clean.1.zip",
  "2018-07-28-clean.0.zip",
  "2018-07-28-clean.1.zip",
  "2018-07-29-clean.0.zip",
  "2018-07-29-clean.1.zip",
  "2018-07-30-clean.0.zip",
  "2018-07-30-clean.1.zip",
  "2018-07-31-clean.0"));
}

代码示例来源:origin: tony19/logback-android

/**
 * Test whether FixedWindowRollingPolicy throws an exception when the
 * ActiveFileName is not set.
 */
@Test(expected = IllegalStateException.class)
public void activeFileNameNotSet() {
 sizeBasedTriggeringPolicy.setMaxFileSize(new FileSize(100));
 sizeBasedTriggeringPolicy.start();
 fwrp.setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX + "sizeBased-test1.%i");
 fwrp.start();
 // The absence of activeFileName option should cause an exception.
}

代码示例来源:origin: org.jmxtrans/jmxtrans-output-logback

protected Appender buildAppender(String loggerName, String fileStr) {
  final RollingFileAppender appender = new RollingFileAppender();
  appender.setName(loggerName + "RollingFile");
  appender.setContext(loggerContext);
  appender.setImmediateFlush(true);
  appender.setBufferSize(new FileSize(LOG_IO_BUFFER_SIZE_BYTES));
  appender.setFile(fileStr);
  appender.setEncoder(buildEncoder());
  TriggeringPolicy triggeringPolicy = buildTriggeringPolicy();
  if (triggeringPolicy != null) {
    appender.setTriggeringPolicy(triggeringPolicy);
  }
  appender.setRollingPolicy(buildRollingPolicy(appender, fileStr));
  appender.start();
  return appender;
}

代码示例来源:origin: tony19/logback-android

void generic(String testName, String fileName, String filenamePattern, List<String> expectedFilenameList) throws InterruptedException, IOException {
 rfa.setName("ROLLING");
 initRFA(randomOutputDir + fileName);
 sizeBasedTriggeringPolicy.setMaxFileSize(new FileSize(100));
 fwrp.setMinIndex(0);
 fwrp.setFileNamePattern(randomOutputDir + filenamePattern);
 rfa.triggeringPolicy = sizeBasedTriggeringPolicy;
 rfa.rollingPolicy = fwrp;
 fwrp.start();
 sizeBasedTriggeringPolicy.start();
 rfa.start();
 int runLength = 40;
 String prefix = "hello";
 for (int i = 0; i < runLength; i++){
  Thread.sleep(10);
  rfa.doAppend(prefix + i);
 }
 rfa.stop();
 existenceCheck(expectedFilenameList);
 reverseSortedContentCheck(randomOutputDir, runLength, prefix);
}

代码示例来源:origin: tony19/logback-android

private void initPolicies(RollingFileAppender<Object> rfa,
             TimeBasedRollingPolicy<Object> tbrp,
             String filenamePattern, int sizeThreshold,
             long givenTime) {
 sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<Object>();
 tbrp.setContext(context);
 sizeAndTimeBasedFNATP.setMaxFileSize(new FileSize(sizeThreshold));
 tbrp.setTimeBasedFileNamingAndTriggeringPolicy(sizeAndTimeBasedFNATP);
 tbrp.setFileNamePattern(filenamePattern);
 tbrp.setParent(rfa);
 tbrp.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(givenTime);
 rfa.setRollingPolicy(tbrp);
 tbrp.start();
 rfa.start();
}

代码示例来源:origin: tony19/logback-android

private void buildRollingFileAppender(ConfigParameters cp) {
 rfa.setContext(context);
 rfa.setEncoder(encoder);
 tbrp.setContext(context);
 tbrp.setFileNamePattern(cp.fileNamePattern);
 tbrp.setMaxHistory(cp.maxHistory);
 tbrp.setTotalSizeCap(new FileSize(cp.sizeCap));
 tbrp.setParent(rfa);
 tbrp.setCleanHistoryOnStart(false);
 tbrp.timeBasedFileNamingAndTriggeringPolicy = tbfnatp;
 tbrp.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(cp.simulatedTime);
 tbrp.start();
 rfa.setRollingPolicy(tbrp);
 rfa.start();
}

相关文章