use of ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy in project spring-boot by spring-projects.
the class LogbackConfigurationTests method defaultRollingFileNamePattern.
@Test
void defaultRollingFileNamePattern() throws JoranException {
JoranConfigurator configurator = new JoranConfigurator();
LoggerContext context = new LoggerContext();
configurator.setContext(context);
configurator.doConfigure(new File("src/test/resources/custom-file-log-pattern.xml"));
Appender<ILoggingEvent> appender = context.getLogger("ROOT").getAppender("FILE");
assertThat(appender).isInstanceOf(RollingFileAppender.class);
RollingPolicy rollingPolicy = ((RollingFileAppender<?>) appender).getRollingPolicy();
String fileNamePattern = ((SizeAndTimeBasedRollingPolicy<?>) rollingPolicy).getFileNamePattern();
assertThat(fileNamePattern).endsWith("spring.log.%d{yyyy-MM-dd}.%i.gz");
}
use of ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy in project jmxtrans by jmxtrans.
the class DailyKeyOutWriter method buildRollingPolicy.
@Override
protected RollingPolicy buildRollingPolicy(FileAppender<?> appender, String fileStr) {
SizeAndTimeBasedRollingPolicy rollingPolicy = new SizeAndTimeBasedRollingPolicy();
rollingPolicy.setParent(appender);
rollingPolicy.setContext(loggerContext);
if (getMaxLogFileSize() == null) {
rollingPolicy.setFileNamePattern(fileStr + "%d{" + datePattern + "}");
} else {
rollingPolicy.setMaxFileSize(FileSize.valueOf(getMaxLogFileSize()));
rollingPolicy.setFileNamePattern(fileStr + "%d{" + datePattern + "}.%i");
}
rollingPolicy.setMaxHistory(getMaxLogBackupFiles());
rollingPolicy.start();
return rollingPolicy;
}
use of ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy in project grakn by graknlabs.
the class CoreLogback method fileAppender.
protected static RollingFileAppender<ILoggingEvent> fileAppender(String name, LoggerContext context, LayoutWrappingEncoder<ILoggingEvent> encoder, TTLLLayout layout, CoreConfig.Log.Output.Type.File outputType) {
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
appender.setContext(context);
appender.setName(name);
appender.setAppend(true);
String logPath = outputType.asFile().path().resolve(TYPEDB_LOG_FILE).toAbsolutePath().toString();
appender.setFile(logPath);
appender.setLayout(layout);
appender.setEncoder(encoder);
SizeAndTimeBasedRollingPolicy<?> policy = new SizeAndTimeBasedRollingPolicy<>();
policy.setContext(context);
policy.setFileNamePattern(logPath + TYPEDB_LOG_FILE_ARCHIVE_SUFFIX);
long directorySize = outputType.fileSizeCap() + outputType.archivesSizeCap();
policy.setMaxFileSize(new FileSize(outputType.fileSizeCap()));
policy.setTotalSizeCap(new FileSize(directorySize));
policy.setParent(appender);
policy.start();
appender.setRollingPolicy(policy);
appender.start();
return appender;
}
use of ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy in project aion by aionnetwork.
the class AionLoggerFactory method constructAppenders.
private static List<Appender<ILoggingEvent>> constructAppenders(boolean shouldLogToFile, String _logDirectory) {
List<Appender<ILoggingEvent>> appenders = new ArrayList<>();
String logDirectory = DEFAULT_LOG_DIR;
if (_logDirectory != null && !_logDirectory.trim().isEmpty())
logDirectory = _logDirectory;
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(context);
encoder.setPattern(DEFAULT_LOG_PATTERN);
encoder.start();
ConsoleAppender<ILoggingEvent> consoleSync = new ConsoleAppender<>();
consoleSync.setContext(context);
// for logger debugging
consoleSync.setName("consoleSyncAppender");
consoleSync.setEncoder(encoder);
consoleSync.start();
AsyncAppender consoleAsync = new AsyncAppender();
consoleAsync.setContext(context);
// for logger debugging
consoleAsync.setName("consoleAsyncAppender");
consoleAsync.addAppender(consoleSync);
consoleAsync.setIncludeCallerData(ASYNC_LOGGER_INCLUDE_CALLER_DATA);
consoleAsync.setNeverBlock(ASYNC_LOGGER_NEVER_BLOCK);
consoleAsync.setMaxFlushTime(ASYNC_LOGGER_MAX_FLUSH_TIME_MS);
consoleAsync.setDiscardingThreshold(ASYNC_LOGGER_DISCARDING_THRESHOLD);
consoleAsync.setQueueSize(ASYNC_LOGGER_QUEUE_SIZE);
consoleAsync.start();
appenders.add(consoleAsync);
if (!shouldLogToFile)
return appenders;
RollingFileAppender<ILoggingEvent> fileSync = new RollingFileAppender<>();
SizeBasedTriggeringPolicy<ILoggingEvent> tp = new SizeBasedTriggeringPolicy<>();
tp.setContext(context);
tp.start();
SizeAndTimeBasedRollingPolicy rp = new SizeAndTimeBasedRollingPolicy();
rp.setContext(context);
// roll-over each day
// notice that we don't use the OS-agnostic File.separator here since logback is converts
// the FileNamePattern
// to a unix-style path using ch.qos.logback.core.rolling.helper.FileFilterUtil.slashify
FileNamePattern fnp = new FileNamePattern(logDirectory + "/%d{yyyy/MM, aux}/aion.%d{yyyy-MM-dd}.%i.log", context);
rp.setFileNamePattern(fnp.getPattern());
// max rollover file size = 100MB
rp.setMaxFileSize(FileSize.valueOf("100mb"));
rp.setParent(fileSync);
rp.start();
// for logger debugging
fileSync.setName("fileSyncAppender");
fileSync.setContext(context);
fileSync.setTriggeringPolicy(tp);
fileSync.setRollingPolicy(rp);
fileSync.setFile(logDirectory + File.separator + DEFAULT_LOG_FILE_CURRENT);
fileSync.setEncoder(encoder);
fileSync.setAppend(true);
fileSync.start();
AsyncAppender fileAsync = new AsyncAppender();
fileAsync.setContext(context);
// for logger debugging
fileAsync.setName("fileAsyncAppender");
fileAsync.addAppender(fileSync);
fileAsync.setIncludeCallerData(ASYNC_LOGGER_INCLUDE_CALLER_DATA);
fileAsync.setNeverBlock(ASYNC_LOGGER_NEVER_BLOCK);
fileAsync.setMaxFlushTime(ASYNC_LOGGER_MAX_FLUSH_TIME_MS);
fileAsync.setDiscardingThreshold(ASYNC_LOGGER_DISCARDING_THRESHOLD);
fileAsync.setQueueSize(ASYNC_LOGGER_QUEUE_SIZE);
fileAsync.start();
appenders.add(fileAsync);
return appenders;
}
use of ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy in project dropwizard by dropwizard.
the class FileAppenderFactory method buildAppender.
protected FileAppender<E> buildAppender(LoggerContext context) {
if (archive) {
final RollingFileAppender<E> appender = new RollingFileAppender<>();
appender.setContext(context);
appender.setFile(currentLogFilename);
appender.setBufferSize(new FileSize(bufferSize.toBytes()));
if (maxFileSize != null && !requireNonNull(archivedLogFilenamePattern).contains("%d")) {
final FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setContext(context);
rollingPolicy.setMaxIndex(getArchivedFileCount());
rollingPolicy.setFileNamePattern(getArchivedLogFilenamePattern());
rollingPolicy.setParent(appender);
rollingPolicy.start();
appender.setRollingPolicy(rollingPolicy);
final SizeBasedTriggeringPolicy<E> triggeringPolicy = new SizeBasedTriggeringPolicy<>();
triggeringPolicy.setMaxFileSize(new FileSize(maxFileSize.toBytes()));
triggeringPolicy.setContext(context);
triggeringPolicy.start();
appender.setTriggeringPolicy(triggeringPolicy);
return appender;
} else {
final TimeBasedRollingPolicy<E> rollingPolicy;
if (maxFileSize == null) {
rollingPolicy = new TimeBasedRollingPolicy<>();
final TimeBasedFileNamingAndTriggeringPolicy<E> triggeringPolicy = new DefaultTimeBasedFileNamingAndTriggeringPolicy<>();
triggeringPolicy.setContext(context);
triggeringPolicy.setTimeBasedRollingPolicy(rollingPolicy);
appender.setTriggeringPolicy(triggeringPolicy);
} else {
// Creating a size and time policy does not need a separate triggering policy set
// on the appender because this policy registers the trigger policy
final SizeAndTimeBasedRollingPolicy<E> sizeAndTimeBasedRollingPolicy = new SizeAndTimeBasedRollingPolicy<>();
sizeAndTimeBasedRollingPolicy.setMaxFileSize(new FileSize(maxFileSize.toBytes()));
rollingPolicy = sizeAndTimeBasedRollingPolicy;
}
if (totalSizeCap != null) {
rollingPolicy.setTotalSizeCap(new FileSize(totalSizeCap.toBytes()));
}
rollingPolicy.setContext(context);
rollingPolicy.setFileNamePattern(archivedLogFilenamePattern);
rollingPolicy.setMaxHistory(archivedFileCount);
appender.setRollingPolicy(rollingPolicy);
rollingPolicy.setParent(appender);
rollingPolicy.start();
return appender;
}
}
final FileAppender<E> appender = new FileAppender<>();
appender.setContext(context);
appender.setFile(currentLogFilename);
appender.setBufferSize(new FileSize(bufferSize.toBytes()));
return appender;
}
Aggregations