ch.qos.logback.core.rolling.RollingPolicyBase Java Examples

The following examples show how to use ch.qos.logback.core.rolling.RollingPolicyBase. 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: RollingPolicyResource.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
public RollingPolicyResource(RollingPolicyBase policy) {
	fileNamePattern = policy.getFileNamePattern();
	compressionMode = policy.getCompressionMode();
}
 
Example #4
Source File: AppenderUtils.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
public static void configureRollingFileAppender(FileLoggerSettings fileLoggerSettings,
                                                Context loggerContext,
                                                RollingFileAppender<ILoggingEvent> appender)
{
    String fileName = fileLoggerSettings.getFileName();
    File file = new File(fileName);
    if (file.getParentFile() != null)
    {
        file.getParentFile().mkdirs();
    }
    validateLogFilePermissions(file);
    validateMaxFileSize(fileLoggerSettings.getMaxFileSize());

    appender.setFile(fileName);
    appender.setAppend(true);
    appender.setContext(loggerContext);

    TriggeringPolicy triggeringPolicy;
    RollingPolicyBase rollingPolicy;
    final String maxFileSizeAsString = String.valueOf(fileLoggerSettings.getMaxFileSize()) + "MB";
    if(fileLoggerSettings.isRollDaily())
    {
        DailyTriggeringPolicy dailyTriggeringPolicy = new DailyTriggeringPolicy(fileLoggerSettings.isRollOnRestart(), maxFileSizeAsString);
        dailyTriggeringPolicy.setContext(loggerContext);
        TimeBasedRollingPolicy<ILoggingEvent> timeBasedRollingPolicy = new TimeBasedRollingPolicy<>();
        timeBasedRollingPolicy.setMaxHistory(fileLoggerSettings.getMaxHistory());
        timeBasedRollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(dailyTriggeringPolicy);
        timeBasedRollingPolicy.setFileNamePattern(fileName + ".%d{yyyy-MM-dd}.%i" + (fileLoggerSettings.isCompressOldFiles()
                ? ".gz"
                : ""));
        rollingPolicy = timeBasedRollingPolicy;
        triggeringPolicy = dailyTriggeringPolicy;
    }
    else
    {
        SizeTriggeringPolicy sizeTriggeringPolicy = new SizeTriggeringPolicy(fileLoggerSettings.isRollOnRestart(), maxFileSizeAsString);
        sizeTriggeringPolicy.setContext(loggerContext);
        SimpleRollingPolicy simpleRollingPolicy = new SimpleRollingPolicy(fileLoggerSettings.getMaxHistory());
        simpleRollingPolicy.setFileNamePattern(fileName + ".%i" + (fileLoggerSettings.isCompressOldFiles() ? ".gz" : ""));
        rollingPolicy = simpleRollingPolicy;
        triggeringPolicy = sizeTriggeringPolicy;
    }

    rollingPolicy.setContext(loggerContext);
    RollingPolicyDecorator decorator = new RollingPolicyDecorator(rollingPolicy, fileLoggerSettings.getRolloverListener(), fileLoggerSettings.getExecutorService());
    decorator.setParent(appender);
    appender.setRollingPolicy(decorator);
    appender.setTriggeringPolicy(triggeringPolicy);
    decorator.start();
    triggeringPolicy.start();

    final PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setPattern(fileLoggerSettings.getLayout());
    encoder.setContext(loggerContext);
    encoder.start();
    appender.setEncoder(encoder);
}
 
Example #5
Source File: RollingPolicyDecorator.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
public RollingPolicyBase getDecorated()
{
    return _decorated;
}