use of ch.qos.logback.core.rolling.helper.FileNamePattern in project qpid-broker-j by apache.
the class RollingPolicyDecoratorTest method setUp.
@Before
public void setUp() throws Exception {
_baseFolder = TestFileUtils.createTestDirectory("rollover", true);
_testFile = createTestFile("test.2015-06-25.0.gz");
Context mockContext = mock(Context.class);
_delegate = mock(RollingPolicyBase.class);
String fileNamePattern = _baseFolder.getAbsolutePath() + "/" + "test.%d{yyyy-MM-dd}.%i.gz";
when(_delegate.getFileNamePattern()).thenReturn(fileNamePattern);
when(_delegate.getContext()).thenReturn(mockContext);
_listener = mock(RollingPolicyDecorator.RolloverListener.class);
_policy = new RollingPolicyDecorator(_delegate, _listener, createMockExecutorService());
_rolledFileRegExp = Pattern.compile(new FileNamePattern(fileNamePattern, mockContext).toRegex());
LOGGER.debug("Rolled file reg exp: {} ", _rolledFileRegExp);
}
use of ch.qos.logback.core.rolling.helper.FileNamePattern 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.helper.FileNamePattern 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();
}
Aggregations