org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy Java Examples

The following examples show how to use org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy. 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: Log4JLogConfigInitializer.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns a rolling file appender.
 *
 * @param file the file to output to, including path and filename.
 */
private RollingFileAppender getRollingFileAppender( String file )
{
    RollingFileAppender appender = RollingFileAppender.newBuilder().withFileName( file )
        .setName("appender_" + file)
        .withFilePattern( file + "%i")
        .setLayout( PATTERN_LAYOUT )
        .withPolicy(
            SizeBasedTriggeringPolicy.createPolicy( config.getProperty( ConfigurationKey.LOGGING_FILE_MAX_SIZE ) ) )
        .withStrategy( DefaultRolloverStrategy.newBuilder()
            .withMax( config.getProperty( ConfigurationKey.LOGGING_FILE_MAX_ARCHIVES ) ).build() )
        .build();

    appender.start();
    return appender;
}
 
Example #2
Source File: Log4j1ConfigurationFactoryTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private void testRollingFileAppender(final String configResource, final String name, final String filePattern) throws URISyntaxException {
	final Configuration configuration = getConfiguration(configResource);
	final Appender appender = configuration.getAppender(name);
	assertNotNull(appender);
	assertEquals(name, appender.getName());
	assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
	final RollingFileAppender rfa = (RollingFileAppender) appender;
	assertEquals("target/hadoop.log", rfa.getFileName());
	assertEquals(filePattern, rfa.getFilePattern());
	final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
	assertNotNull(triggeringPolicy);
	assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
	final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
	final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
	assertEquals(1, triggeringPolicies.length);
	final TriggeringPolicy tp = triggeringPolicies[0];
	assertTrue(tp.getClass().getName(), tp instanceof SizeBasedTriggeringPolicy);
	final SizeBasedTriggeringPolicy sbtp = (SizeBasedTriggeringPolicy) tp;
	assertEquals(256 * 1024 * 1024, sbtp.getMaxFileSize());
	final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
	assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
	final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
	assertEquals(20, drs.getMaxIndex());
	configuration.start();
	configuration.stop();
}
 
Example #3
Source File: Log4j1ConfigurationFactoryTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private void testDailyRollingFileAppender(final String configResource, final String name, final String filePattern) throws URISyntaxException {
	final Configuration configuration = getConfiguration(configResource);
	final Appender appender = configuration.getAppender(name);
	assertNotNull(appender);
	assertEquals(name, appender.getName());
	assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
	final RollingFileAppender rfa = (RollingFileAppender) appender;
	assertEquals("target/hadoop.log", rfa.getFileName());
	assertEquals(filePattern, rfa.getFilePattern());
	final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
	assertNotNull(triggeringPolicy);
	assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
	final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
	final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
	assertEquals(1, triggeringPolicies.length);
	final TriggeringPolicy tp = triggeringPolicies[0];
	assertTrue(tp.getClass().getName(), tp instanceof TimeBasedTriggeringPolicy);
	final TimeBasedTriggeringPolicy tbtp = (TimeBasedTriggeringPolicy) tp;
	assertEquals(1, tbtp.getInterval());
	final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
	assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
	final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
	assertEquals(Integer.MAX_VALUE, drs.getMaxIndex());
	configuration.start();
	configuration.stop();
}
 
Example #4
Source File: Log4j1ConfigurationFactoryTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private void testRollingFileAppender(final String configResource, final String name, final String filePattern) throws URISyntaxException {
	final Configuration configuration = getConfiguration(configResource);
	final Appender appender = configuration.getAppender(name);
	assertNotNull(appender);
	assertEquals(name, appender.getName());
	assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
	final RollingFileAppender rfa = (RollingFileAppender) appender;
	assertEquals("target/hadoop.log", rfa.getFileName());
	assertEquals(filePattern, rfa.getFilePattern());
	final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
	assertNotNull(triggeringPolicy);
	assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
	final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
	final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
	assertEquals(1, triggeringPolicies.length);
	final TriggeringPolicy tp = triggeringPolicies[0];
	assertTrue(tp.getClass().getName(), tp instanceof SizeBasedTriggeringPolicy);
	final SizeBasedTriggeringPolicy sbtp = (SizeBasedTriggeringPolicy) tp;
	assertEquals(256 * 1024 * 1024, sbtp.getMaxFileSize());
	final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
	assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
	final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
	assertEquals(20, drs.getMaxIndex());
	configuration.start();
	configuration.stop();
}
 
Example #5
Source File: Log4j1ConfigurationFactoryTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private void testDailyRollingFileAppender(final String configResource, final String name, final String filePattern) throws URISyntaxException {
	final Configuration configuration = getConfiguration(configResource);
	final Appender appender = configuration.getAppender(name);
	assertNotNull(appender);
	assertEquals(name, appender.getName());
	assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
	final RollingFileAppender rfa = (RollingFileAppender) appender;
	assertEquals("target/hadoop.log", rfa.getFileName());
	assertEquals(filePattern, rfa.getFilePattern());
	final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
	assertNotNull(triggeringPolicy);
	assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
	final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
	final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
	assertEquals(1, triggeringPolicies.length);
	final TriggeringPolicy tp = triggeringPolicies[0];
	assertTrue(tp.getClass().getName(), tp instanceof TimeBasedTriggeringPolicy);
	final TimeBasedTriggeringPolicy tbtp = (TimeBasedTriggeringPolicy) tp;
	assertEquals(1, tbtp.getInterval());
	final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
	assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
	final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
	assertEquals(Integer.MAX_VALUE, drs.getMaxIndex());
	configuration.start();
	configuration.stop();
}
 
Example #6
Source File: Log4j2Util.java    From summerframework with Apache License 2.0 5 votes vote down vote up
private static DefaultRolloverStrategy createStrategyByAction(String loggerName, String loggerDir) {

        IfFileName ifFileName = IfFileName.createNameCondition(null, loggerName + "\\.\\d{4}-\\d{2}-\\d{2}.*");
        IfLastModified ifLastModified = IfLastModified.createAgeCondition(Duration.parse("1d"));
        DeleteAction deleteAction = DeleteAction.createDeleteAction(loggerDir, false, 1, false, null,
            new PathCondition[] {ifLastModified, ifFileName}, null, config);
        Action[] actions = new Action[] {deleteAction};

        return DefaultRolloverStrategy.createStrategy("7", "1", null, null, actions, false, config);
    }
 
Example #7
Source File: DailyRollingFileAppenderBuilder.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private <T extends Log4j1Configuration> Appender createAppender(final String name, final Layout layout,
        final Filter filter, final String fileName, final boolean append, boolean immediateFlush,
        final String level, final boolean bufferedIo, final int bufferSize, final T configuration) {

    org.apache.logging.log4j.core.Layout<?> fileLayout = null;
    if (bufferedIo) {
        immediateFlush = true;
    }
    if (layout instanceof LayoutWrapper) {
        fileLayout = ((LayoutWrapper) layout).getLayout();
    } else if (layout != null) {
        fileLayout = new LayoutAdapter(layout);
    }
    org.apache.logging.log4j.core.Filter fileFilter = buildFilters(level, filter);
    if (fileName == null) {
        LOGGER.warn("Unable to create File Appender, no file name provided");
        return null;
    }
    String filePattern = fileName +"%d{yyy-MM-dd}";
    TriggeringPolicy policy = TimeBasedTriggeringPolicy.newBuilder().setModulate(true).build();
    RolloverStrategy strategy = DefaultRolloverStrategy.newBuilder()
            .setConfig(configuration)
            .setMax(Integer.toString(Integer.MAX_VALUE))
            .build();
    return new AppenderWrapper(RollingFileAppender.newBuilder()
            .setName(name)
            .setConfiguration(configuration)
            .setLayout(fileLayout)
            .setFilter(fileFilter)
            .setFileName(fileName)
            .setBufferSize(bufferSize)
            .setImmediateFlush(immediateFlush)
            .setFilePattern(filePattern)
            .setPolicy(policy)
            .setStrategy(strategy)
            .build());
}
 
Example #8
Source File: RollingFileAppenderBuilder.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private Appender createAppender(final String name, final Log4j1Configuration config, final Layout layout,
        final Filter filter, final boolean bufferedIo, boolean immediateFlush, final String fileName,
        final String level, final String maxSize, final String maxBackups) {
    org.apache.logging.log4j.core.Layout<?> fileLayout = null;
    if (bufferedIo) {
        immediateFlush = true;
    }
    if (layout instanceof LayoutWrapper) {
        fileLayout = ((LayoutWrapper) layout).getLayout();
    } else if (layout != null) {
        fileLayout = new LayoutAdapter(layout);
    }
    org.apache.logging.log4j.core.Filter fileFilter = buildFilters(level, filter);
    if (fileName == null) {
        LOGGER.warn("Unable to create File Appender, no file name provided");
        return null;
    }
    String filePattern = fileName +"%d{yyy-MM-dd}";
    TriggeringPolicy timePolicy = TimeBasedTriggeringPolicy.newBuilder().setModulate(true).build();
    SizeBasedTriggeringPolicy sizePolicy = SizeBasedTriggeringPolicy.createPolicy(maxSize);
    CompositeTriggeringPolicy policy = CompositeTriggeringPolicy.createPolicy(sizePolicy, timePolicy);
    RolloverStrategy strategy = DefaultRolloverStrategy.newBuilder()
            .setConfig(config)
            .setMax(maxBackups)
            .build();
    return new AppenderWrapper(RollingFileAppender.newBuilder()
            .setName(name)
            .setConfiguration(config)
            .setLayout(fileLayout)
            .setFilter(fileFilter)
            .setBufferedIo(bufferedIo)
            .setImmediateFlush(immediateFlush)
            .setFileName(fileName)
            .setFilePattern(filePattern)
            .setPolicy(policy)
            .setStrategy(strategy)
            .build());
}
 
Example #9
Source File: CloudStorageLoggerFactory.java    From ambari-logsearch with Apache License 2.0 4 votes vote down vote up
public static Logger createLogger(Input input, LoggerContext loggerContext, LogFeederProps logFeederProps) {
  boolean useJsonFormat = logFeederProps.isCloudStorageUseFilters();
  String type = input.getLogType().replace(LogFeederConstants.CLOUD_PREFIX, "");
  String uniqueThreadName = input.getThread().getName();
  Configuration config = loggerContext.getConfiguration();
  String baseDir = logFeederProps.getRolloverConfig().getRolloverArchiveBaseDir();
  String destination = logFeederProps.getCloudStorageDestination().getText();
  String clusterHostnameBaseDir = Paths.get(baseDir, destination, logFeederProps.getClusterName(), LogFeederUtil.hostName).toFile().getAbsolutePath();
  String activeLogDir = Paths.get(clusterHostnameBaseDir, ACTIVE_FOLDER, type).toFile().getAbsolutePath();
  String archiveLogDir = Paths.get(clusterHostnameBaseDir, ARCHIVED_FOLDER, type).toFile().getAbsolutePath();

  boolean useGzip = logFeederProps.getRolloverConfig().isUseGzip();
  final String archiveFilePattern;
  if (useJsonFormat) {
    archiveFilePattern = useGzip ? JSON_DATE_PATTERN_SUFFIX_GZ : JSON_DATE_PATTERN_SUFFIX;
  } else {
    archiveFilePattern = useGzip ? DATE_PATTERN_SUFFIX_GZ : DATE_PATTERN_SUFFIX;
  }

  String logSuffix = useJsonFormat ? ".json" : ".log";
  String fileName = String.join(File.separator, activeLogDir, type + logSuffix);
  String filePattern = String.join(File.separator, archiveLogDir, type + archiveFilePattern);
  PatternLayout layout = PatternLayout.newBuilder()
    .withPattern(PatternLayout.DEFAULT_CONVERSION_PATTERN).build();

  String rolloverSize = logFeederProps.getRolloverConfig().getRolloverSize().toString() + logFeederProps.getRolloverConfig().getRolloverSizeFormat();
  SizeBasedTriggeringPolicy sizeBasedTriggeringPolicy = SizeBasedTriggeringPolicy.createPolicy(rolloverSize);

  final Integer thresholdMin = logFeederProps.getRolloverConfig().getRolloverThresholdTimeMins();
  final Integer thresholdInterval = thresholdMin * 60000; // 1 min = 60000 milliseconds

  TimeBasedTriggeringPolicy timeBasedTriggeringPolicy = TimeBasedTriggeringPolicy.newBuilder()
    .withInterval(thresholdInterval)
    .build();

  final CompositeTriggeringPolicy compositeTriggeringPolicy;

  if (logFeederProps.getRolloverConfig().isRolloverOnStartup()) {
    OnStartupTriggeringPolicy onStartupTriggeringPolicy = OnStartupTriggeringPolicy.createPolicy(1);
    compositeTriggeringPolicy = CompositeTriggeringPolicy
      .createPolicy(sizeBasedTriggeringPolicy, timeBasedTriggeringPolicy, onStartupTriggeringPolicy);
  } else {
    compositeTriggeringPolicy = CompositeTriggeringPolicy
      .createPolicy(sizeBasedTriggeringPolicy, timeBasedTriggeringPolicy);
  }

  DefaultRolloverStrategy defaultRolloverStrategy = DefaultRolloverStrategy.newBuilder()
    .withMax(String.valueOf(logFeederProps.getRolloverConfig().getRolloverMaxBackupFiles()))
    .build();

  boolean immediateFlush = logFeederProps.getRolloverConfig().isImmediateFlush();
  RollingFileAppender appender = RollingFileAppender.newBuilder()
    .withFileName(fileName)
    .withFilePattern(filePattern)
    .withLayout(layout)
    .withName(type)
    .withPolicy(compositeTriggeringPolicy)
    .withStrategy(defaultRolloverStrategy)
    .withImmediateFlush(immediateFlush)
    .build();

  appender.start();
  config.addAppender(appender);

  AppenderRef ref = AppenderRef.createAppenderRef(type, null, null);
  AppenderRef[] refs = new AppenderRef[] {ref};

  LoggerConfig loggerConfig = LoggerConfig
    .createLogger(false, Level.ALL, input.getThread().getName(),
      "true", refs, null, config, null);
  loggerConfig.addAppender(appender, null, null);
  config.addLogger(uniqueThreadName, loggerConfig);
  loggerContext.updateLoggers();
  return loggerContext.getLogger(uniqueThreadName);
}
 
Example #10
Source File: ApsSystemUtils.java    From entando-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void init() throws Exception {
    String active = (String) this.systemParams.get(INIT_PROP_LOG_ACTIVE_FILE_OUTPUT);
    if (StringUtils.isEmpty(active) || !active.equalsIgnoreCase("true")) {
        return;
    }
    String appenderName = "ENTANDO";
    String conversionPattern = (String) this.systemParams.get("log4jConversionPattern");
    if (StringUtils.isBlank(conversionPattern)) {
        conversionPattern = "%d{yyyy-MM-dd HH:mm:ss.SSS} - %-5p -  %c - %m%n";
    }
    String maxFileSize = (String) this.systemParams.get(INIT_PROP_LOG_FILE_SIZE);
    if (StringUtils.isBlank(maxFileSize)) {
        maxFileSize = "1MB"; //default size
    } else {
        long mega = new Long(maxFileSize) / KILOBYTE;
        maxFileSize = mega + "KB";
    }
    String filePattern = (String) this.systemParams.get(INIT_PROP_LOG_FILE_PATTERN);
    String filename = (String) this.systemParams.get(INIT_PROP_LOG_NAME);
    int maxBackupIndex = Integer.parseInt((String) this.systemParams.get(INIT_PROP_LOG_FILES_COUNT));
    String log4jLevelString = (String) this.systemParams.get(INIT_PROP_LOG_LEVEL);
    if (StringUtils.isBlank(log4jLevelString)) {
        log4jLevelString = "INFO"; //default level
    }
    Configurator.setRootLevel(Level.getLevel(log4jLevelString));
    LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
    loggerContext.getRootLogger().setLevel(Level.getLevel(log4jLevelString));
    Configurator.setAllLevels(loggerContext.getRootLogger().getName(), Level.getLevel(log4jLevelString));
    Configuration configuration = loggerContext.getConfiguration();
    RollingFileAppender fileAppender = (RollingFileAppender) configuration.getAppender(appenderName);
    if (null == fileAppender) {
        PathCondition[] pathConditions = new PathCondition[]{IfAccumulatedFileCount.createFileCountCondition(maxBackupIndex)};
        String basePath = filePattern.substring(0, filePattern.lastIndexOf(File.separator));
        DeleteAction deleteAction = DeleteAction.createDeleteAction(basePath, true, 1, false, null, pathConditions, null, configuration);
        SizeBasedTriggeringPolicy policy = SizeBasedTriggeringPolicy.createPolicy(maxFileSize);
        PatternLayout layout = PatternLayout.newBuilder().withPattern(conversionPattern).build();
        DefaultRolloverStrategy strategy = DefaultRolloverStrategy.newBuilder()
                .withConfig(configuration).withMax(String.valueOf(maxBackupIndex))
                .withCustomActions(new Action[]{deleteAction}).build();
        fileAppender = RollingFileAppender.newBuilder()
                .withName(appenderName)
                .setConfiguration(configuration)
                .withLayout(layout)
                .withFileName(filename)
                .withFilePattern(filePattern)
                .withPolicy(policy)
                .withStrategy(strategy)
                .build();
        configuration.addAppender(fileAppender);
        Configurator.setLevel(appenderName, Level.getLevel(log4jLevelString));
        fileAppender.start();
    }
    AsyncAppender async = (AsyncAppender) loggerContext.getRootLogger().getAppenders().get("async");
    if (null == async) {
        AppenderRef ref = AppenderRef.createAppenderRef(appenderName, Level.getLevel(log4jLevelString), null);
        async = AsyncAppender.newBuilder().setName("async")
                .setConfiguration(configuration)
                .setAppenderRefs(new AppenderRef[]{ref}).build();
        configuration.addAppender(async);
        loggerContext.getRootLogger().addAppender(async);
        async.start();
    }
    loggerContext.updateLoggers();
}
 
Example #11
Source File: RollingFileAppender.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public RollingFileAppender build() {
    // Even though some variables may be annotated with @Required, we must still perform validation here for
    // call sites that build builders programmatically.
    final boolean isBufferedIo = isBufferedIo();
    final int bufferSize = getBufferSize();
    if (getName() == null) {
        LOGGER.error("RollingFileAppender '{}': No name provided.", getName());
        return null;
    }

    if (!isBufferedIo && bufferSize > 0) {
        LOGGER.warn("RollingFileAppender '{}': The bufferSize is set to {} but bufferedIO is not true", getName(), bufferSize);
    }

    if (filePattern == null) {
        LOGGER.error("RollingFileAppender '{}': No file name pattern provided.", getName());
        return null;
    }

    if (policy == null) {
        LOGGER.error("RollingFileAppender '{}': No TriggeringPolicy provided.", getName());
        return null;
    }

    if (strategy == null) {
        if (fileName != null) {
            strategy = DefaultRolloverStrategy.newBuilder()
                                .setCompressionLevelStr(String.valueOf(Deflater.DEFAULT_COMPRESSION))
                                .setConfig(getConfiguration())
                                .build();
        } else {
            strategy = DirectWriteRolloverStrategy.newBuilder()
                                .setCompressionLevelStr(String.valueOf(Deflater.DEFAULT_COMPRESSION))
                                .setConfig(getConfiguration())
                                .build();
        }
    } else if (fileName == null && !(strategy instanceof DirectFileRolloverStrategy)) {
        LOGGER.error("RollingFileAppender '{}': When no file name is provided a DirectFilenameRolloverStrategy must be configured", getName());
        return null;
    }

    final Layout<? extends Serializable> layout = getOrCreateLayout();
    final RollingFileManager manager = RollingFileManager.getFileManager(fileName, filePattern, append,
            isBufferedIo, policy, strategy, advertiseUri, layout, bufferSize, isImmediateFlush(),
            createOnDemand, filePermissions, fileOwner, fileGroup, getConfiguration());
    if (manager == null) {
        return null;
    }

    manager.initialize();

    return new RollingFileAppender(getName(), layout, getFilter(), manager, fileName, filePattern,
            isIgnoreExceptions(), isImmediateFlush(), advertise ? getConfiguration().getAdvertiser() : null);
}
 
Example #12
Source File: RollingRandomAccessFileAppender.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public RollingRandomAccessFileAppender build() {
    final String name = getName();
    if (name == null) {
        LOGGER.error("No name provided for FileAppender");
        return null;
    }

    if (strategy == null) {
        if (fileName != null) {
            strategy = DefaultRolloverStrategy.newBuilder()
                    .setCompressionLevelStr(String.valueOf(Deflater.DEFAULT_COMPRESSION))
                    .setConfig(getConfiguration())
                    .build();
        } else {
            strategy = DirectWriteRolloverStrategy.newBuilder()
                    .setCompressionLevelStr(String.valueOf(Deflater.DEFAULT_COMPRESSION))
                    .setConfig(getConfiguration())
                    .build();
        }
    } else if (fileName == null && !(strategy instanceof DirectFileRolloverStrategy)) {
        LOGGER.error("RollingFileAppender '{}': When no file name is provided a DirectFileRolloverStrategy must be configured", name);
        return null;
    }

    if (filePattern == null) {
        LOGGER.error("No filename pattern provided for FileAppender with name " + name);
        return null;
    }

    if (policy == null) {
        LOGGER.error("A TriggeringPolicy must be provided");
        return null;
    }

    final Layout<? extends Serializable> layout = getOrCreateLayout();

    final boolean immediateFlush = isImmediateFlush();
    final int bufferSize = getBufferSize();
    final RollingRandomAccessFileManager manager = RollingRandomAccessFileManager
            .getRollingRandomAccessFileManager(fileName, filePattern, append, immediateFlush, bufferSize, policy,
                    strategy, advertiseURI, layout,
                    filePermissions, fileOwner, fileGroup, getConfiguration());
    if (manager == null) {
        return null;
    }

    manager.initialize();

    return new RollingRandomAccessFileAppender(name, layout,getFilter(), manager, fileName, filePattern,
            isIgnoreExceptions(), immediateFlush, bufferSize, advertise ? getConfiguration().getAdvertiser() : null);
}