ch.qos.logback.core.rolling.helper.FileNamePattern Java Examples

The following examples show how to use ch.qos.logback.core.rolling.helper.FileNamePattern. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RollingPolicyDecoratorTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: RollingPolicyDecorator.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
public RollingPolicyDecorator(RollingPolicyBase decorated, RolloverListener listener, ScheduledExecutorService executorService)
{
    _decorated = decorated;
    _listener = listener;
    _executorService = executorService;

    String filePathPattern = _decorated.getFileNamePattern();
    String filePathRegExp = new FileNamePattern(filePathPattern, _decorated.getContext()).toRegex();
    FilePathBaseFolderAndPatternPair pair = new FilePathBaseFolderAndPatternPair(filePathRegExp);
    _rolledFilesBaseFolder = pair.getBaseFolder();
    _rolledFileRegExp = pair.getPattern();
    _currentScanTask = null;
}
 
Example #3
Source File: AionLoggerFactory.java    From aion with MIT License 4 votes vote down vote up
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);
    consoleSync.setName("consoleSyncAppender"); // for logger debugging
    consoleSync.setEncoder(encoder);
    consoleSync.start();

    AsyncAppender consoleAsync = new AsyncAppender();
    consoleAsync.setContext(context);
    consoleAsync.setName("consoleAsyncAppender"); // for logger debugging
    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();

    fileSync.setName("fileSyncAppender"); // for logger debugging
    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);
    fileAsync.setName("fileAsyncAppender"); // for logger debugging
    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;
}