private void registerLogFileTailThreads() throws IOException { final Collection<String> outputFileNames = new HashSet<>(); final Collection<Appender> loggerAppenders = this.loggerContext.getConfiguration().getAppenders().values(); loggerAppenders.forEach(appender -> { if (appender instanceof FileAppender) { outputFileNames.add(((FileAppender) appender).getFileName()); } else if (appender instanceof RandomAccessFileAppender) { outputFileNames.add(((RandomAccessFileAppender) appender).getFileName()); } else if (appender instanceof RollingFileAppender) { outputFileNames.add(((RollingFileAppender) appender).getFileName()); } else if (appender instanceof MemoryMappedFileAppender) { outputFileNames.add(((MemoryMappedFileAppender) appender).getFileName()); } else if (appender instanceof RollingRandomAccessFileAppender) { outputFileNames.add(((RollingRandomAccessFileAppender) appender).getFileName()); } }); outputFileNames.forEach(s -> { final Tailer t = new Tailer(new File(s), new LogTailerListener(), 100, false, true); final Thread thread = new Thread(t); thread.setPriority(Thread.MIN_PRIORITY); thread.setName(s); thread.start(); }); }
/** * File appender types do not share a "write-to-file" superclass. */ private String extractFileName(Appender a) { if (a instanceof FileAppender) { return ((FileAppender) a).getFileName(); } else if (a instanceof RollingFileAppender) { return ((RollingFileAppender) a).getFileName(); } else if (a instanceof RollingRandomAccessFileAppender) { return ((RollingRandomAccessFileAppender) a).getFileName(); } else if (a instanceof RandomAccessFileAppender) { return ((RandomAccessFileAppender) a).getFileName(); } else if (a instanceof MemoryMappedFileAppender) { return ((MemoryMappedFileAppender) a).getFileName(); } else { return null; } }
private static RollingFileAppender createFileAppender(String name, String logFile, String maxSizeKey, Map<String, Exception> errors) { RollingFileAppender.Builder builder = RollingFileAppender.newBuilder(); builder.setConfiguration(new NullConfiguration()); builder.withName(name); builder.withLayout(getDetailedLayout()); builder.withFileName(logFile); builder.withFilePattern(logFile); builder.withAppend(true); builder.withImmediateFlush(true); int limit = getLimit(maxSizeKey, errors); if (limit == 0) limit = 900 * 1024 * 1024; // Default in Logging.DEFAULT_MAX_FILE_SIZE builder.withPolicy(SizeBasedTriggeringPolicy.createPolicy(Integer.toString(limit))); return builder.build(); }
private File getLogFolder() { org.apache.logging.log4j.Logger logger = org.apache.logging.log4j.LogManager.getLogger("fr.cls.atoll.motu.web.bll.request"); org.apache.logging.log4j.core.Logger coreLogger = (org.apache.logging.log4j.core.Logger) logger; org.apache.logging.log4j.core.LoggerContext context = coreLogger.getContext(); RollingFileAppender rfa = context.getConfiguration().getAppender("log-file-infos.queue"); String fileNamePattern = rfa.getFileName(); String logFolderStr = StringUtils.substringBeforeLast(fileNamePattern, "/"); File logFolder = null; if (logFolderStr.equalsIgnoreCase("motu-log-dir")) { logFolder = new File(System.getProperty("motu-log-dir")); } else { logFolder = new File(logFolderStr); } return logFolder; }
@Test public void testSystemProperties1() throws Exception { final String tempFileName = System.getProperty("java.io.tmpdir") + "/hadoop.log"; final Path tempFilePath = new File(tempFileName).toPath(); Files.deleteIfExists(tempFilePath); try { final Configuration configuration = getConfiguration("config-1.2/log4j-system-properties-1.properties"); final RollingFileAppender appender = configuration.getAppender("RFA"); appender.stop(10, TimeUnit.SECONDS); System.out.println("expected: " + tempFileName + " Actual: " + appender.getFileName()); assertEquals(tempFileName, appender.getFileName()); } finally { try { Files.deleteIfExists(tempFilePath); } catch (FileSystemException e) { e.printStackTrace(); } } }
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(); }
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(); }
/** * Not a real test, just make sure we can compile access to the typed manager. * * @throws IOException */ @Test public void testAccessManagerWithBuilder() throws IOException { try (final LoggerContext ctx = LoggerContext.getContext(false)) { final Configuration config = ctx.getConfiguration(); final File file = File.createTempFile("RollingFileAppenderAccessTest", ".tmp"); file.deleteOnExit(); // @formatter:off final RollingFileAppender appender = RollingFileAppender.newBuilder() .withFileName(file.getCanonicalPath()) .withFilePattern("FilePattern") .withName("Name") .withPolicy(OnStartupTriggeringPolicy.createPolicy(1)) .setConfiguration(config) .build(); // @formatter:on final RollingFileManager manager = appender.getManager(); // Since the RolloverStrategy and TriggeringPolicy are immutable, we could also use generics to type their // access. Assert.assertNotNull(manager.getRolloverStrategy()); Assert.assertNotNull(manager.getTriggeringPolicy()); } }
/** * Not a real test, just make sure we can compile access to the typed manager. * * @throws IOException */ @Test public void testAccessManagerWithStrings() throws IOException { try (final LoggerContext ctx = LoggerContext.getContext(false)) { final Configuration config = ctx.getConfiguration(); final File file = File.createTempFile("RollingFileAppenderAccessTest", ".tmp"); file.deleteOnExit(); final RollingFileAppender appender = RollingFileAppender.createAppender(file.getCanonicalPath(), "FilePattern", null, "Name", null, null, null, OnStartupTriggeringPolicy.createPolicy(1), null, null, null, null, null, null, config); final RollingFileManager manager = appender.getManager(); // Since the RolloverStrategy and TriggeringPolicy are immutable, we could also use generics to type their // access. Assert.assertNotNull(manager.getRolloverStrategy()); Assert.assertNotNull(manager.getTriggeringPolicy()); } }
@SuppressWarnings("deprecation") private RollingFileAppender initLogger(String loggerName, String filePrefix) { String fileName = Paths.get(rootPath, filePrefix + "." + loggerName + ".dat").toString(); String filePattern = Paths.get(rootPath, filePrefix + "." + loggerName + "-%i.dat").toString(); PatternLayout layout = PatternLayout.newBuilder().withPattern(PatternLayout.DEFAULT_CONVERSION_PATTERN).build(); SizeBasedTriggeringPolicy policy = SizeBasedTriggeringPolicy.createPolicy(maxFileSize); DefaultRolloverStrategy strategy = DefaultRolloverStrategy.createStrategy(String.valueOf(maxFileCount), null, null, null, null, false, config); //TODO:use RollingFileAppender.newBuilder throw No such static method exception,will improve later! return RollingFileAppender .createAppender(fileName, filePattern, "true", loggerName, "true", null, "true", policy, strategy, layout, null, null, null, null, config); }
/** * Creates a new {@link RollingFileAppender} * @param fileName The log file * @param loggingConfig The logging config * @param layout The layout * @param strategy the rollover strategy * @param rolledFileFormat The log file roll pattern * @param trigger The roll trigger * @return the new appender */ protected Appender createRollingFileAppender(final String fileName, Configuration loggingConfig, PatternLayout layout, final DefaultRolloverStrategy strategy, final String rolledFileFormat, final TriggeringPolicy trigger) { RollingFileManager fileManager = RollingFileManager.getFileManager( fileName, rolledFileFormat, false, true, trigger, strategy, null, layout, 8192, true ); trigger.initialize(fileManager); return RollingFileAppender.createAppender( fileName, // file name rolledFileFormat, // rolled file name pattern "true", // append getClass().getSimpleName(), // appender name "true", // buffered io "8192", // buffer size "true", // immediate flush trigger, // triggering policy strategy, // rollover strategy layout, // layout null, // filter "true", // ignore exceptions null, // advertise null, // advertise uri loggingConfig); // config }
/** * Creates a {@link FileAppender}. * * @param configuration the owner configuration * @param fileName the name of log file * @param fileNamePattern the pattern of the name of the log * file * @param appenderName the name of the appender * @param layout the {@link PatternLayout} to use for the * appender * @param rolloverInterval how often the log files should be * rolled over (in DAYS) * @param maximumFilesToKeep the maximum number of file to * keep after every roll-over * @return an instance of {@link Appender} */ protected static Appender createFileAppender(final Configuration configuration, final String fileName, final String fileNamePattern, final String appenderName, final PatternLayout layout, String rolloverInterval, String maximumFilesToKeep) { final String append = Boolean.TRUE.toString(); final String bufferedIO = Boolean.TRUE.toString(); final String bufferSizeStr = null; final String immediateFlush = Boolean.TRUE.toString(); final Filter filter = null; final String ignore = null; final String advertise = null; final String advertiseURI = null; // Trigger Policy final String modulate = Boolean.TRUE.toString(); final TriggeringPolicy policy = TimeBasedTriggeringPolicy.createPolicy(rolloverInterval, modulate); // Rollover strategy final String minFilesToKeep = "1"; final String fileIndex = null; final String compressionLevelStr = Integer.toString(Deflater.DEFAULT_COMPRESSION); final RolloverStrategy rolloverStrategy = DefaultRolloverStrategy.createStrategy( maximumFilesToKeep, minFilesToKeep, fileIndex, compressionLevelStr, configuration); return RollingFileAppender.createAppender(fileName, fileNamePattern, append, appenderName, bufferedIO, bufferSizeStr, immediateFlush, policy, rolloverStrategy, layout, filter, ignore, advertise, advertiseURI, configuration); }
/** {@inheritDoc} */ @Nullable @Override public String fileName() { for (Logger log = impl; log != null; log = log.getParent()) { for (Appender a : log.getAppenders().values()) { if (a instanceof FileAppender) return ((FileAppender)a).getFileName(); if (a instanceof RollingFileAppender) return ((RollingFileAppender)a).getFileName(); if (a instanceof RoutingAppender) { try { RoutingAppender routing = (RoutingAppender)a; Field appsFiled = routing.getClass().getDeclaredField("appenders"); appsFiled.setAccessible(true); Map<String, AppenderControl> appenders = (Map<String, AppenderControl>)appsFiled.get(routing); for (AppenderControl control : appenders.values()) { Appender innerApp = control.getAppender(); if (innerApp instanceof FileAppender) return normalize(((FileAppender)innerApp).getFileName()); if (innerApp instanceof RollingFileAppender) return normalize(((RollingFileAppender)innerApp).getFileName()); } } catch (IllegalAccessException | NoSuchFieldException e) { error("Failed to get file name (was the implementation of log4j2 changed?).", e); } } } } return null; }
private void buildDailyRollingFileAppender(final String appenderName) { final AppenderComponentBuilder appenderBuilder = builder.newAppender(appenderName, RollingFileAppender.PLUGIN_NAME); buildFileAppender(appenderName, appenderBuilder); final String fileName = getLog4jAppenderValue(appenderName, "File"); final String datePattern = getLog4jAppenderValue(appenderName, "DatePattern", fileName + "'.'yyyy-MM-dd"); appenderBuilder.addAttribute("filePattern", fileName + "%d{" + datePattern + "}"); final ComponentBuilder<?> triggeringPolicy = builder.newComponent("Policies") .addComponent(builder.newComponent("TimeBasedTriggeringPolicy").addAttribute("modulate", true)); appenderBuilder.addComponent(triggeringPolicy); appenderBuilder .addComponent(builder.newComponent("DefaultRolloverStrategy").addAttribute("max", Integer.MAX_VALUE)); builder.add(appenderBuilder); }
private void buildRollingFileAppender(final String appenderName) { final AppenderComponentBuilder appenderBuilder = builder.newAppender(appenderName, RollingFileAppender.PLUGIN_NAME); buildFileAppender(appenderName, appenderBuilder); final String fileName = getLog4jAppenderValue(appenderName, "File"); appenderBuilder.addAttribute("filePattern", fileName + ".%i"); final String maxFileSizeString = getLog4jAppenderValue(appenderName, "MaxFileSize", "10485760"); final String maxBackupIndexString = getLog4jAppenderValue(appenderName, "MaxBackupIndex", "1"); final ComponentBuilder<?> triggeringPolicy = builder.newComponent("Policies").addComponent( builder.newComponent("SizeBasedTriggeringPolicy").addAttribute("size", maxFileSizeString)); appenderBuilder.addComponent(triggeringPolicy); appenderBuilder.addComponent( builder.newComponent("DefaultRolloverStrategy").addAttribute("max", maxBackupIndexString)); builder.add(appenderBuilder); }
@Test public void testSystemProperties2() throws Exception { final Configuration configuration = getConfiguration("config-1.2/log4j-system-properties-2.properties"); final RollingFileAppender appender = configuration.getAppender("RFA"); assertEquals("${java.io.tmpdir}/hadoop.log", appender.getFileName()); appender.stop(10, TimeUnit.SECONDS); Path path = new File(appender.getFileName()).toPath(); Files.deleteIfExists(path); path = new File("${java.io.tmpdir}").toPath(); Files.deleteIfExists(path); }
private void testBuilder() { // @formatter:off final RollingFileAppender raf = RollingFileAppender.newBuilder() .withName("test1") .withFileName("target/testcmd1.log") .withFilePattern("target/testcmd1.log.%d{yyyy-MM-dd}") .withPolicy(createPolicy()) .withStrategy(createStrategy()) .setConfiguration(configuration) .build(); // @formatter:on Assert.assertNotNull(raf); }
@Test public void testDefaultLayout() throws Exception { // @formatter:off Assert.assertNotNull(RollingFileAppender.newBuilder() .withName(RollingFileAppenderLayoutTest.class.getName()) .setConfiguration(new DefaultConfiguration()) .withFileName("log.txt") .withFilePattern("FilePattern") .withPolicy(OnStartupTriggeringPolicy.createPolicy(1)) .withCreateOnDemand(true) // no need to clutter up test folder with another file .build().getLayout()); // @formatter:on }
@Test public void testIsCreateOnDemand() { final RollingFileAppender rfAppender = loggerContextRule.getRequiredAppender("RollingFile", RollingFileAppender.class); final RollingFileManager manager = rfAppender.getManager(); Assert.assertNotNull(manager); Assert.assertEquals(createOnDemand, manager.isCreateOnDemand()); }
@Override public void write(String loggerName, String filePrefix, String content) { RollingFileAppender logger = fileAppenders.computeIfAbsent(loggerName, f -> initLogger(loggerName, filePrefix)); logger.append(Log4jLogEvent.newBuilder().setMessage(new SimpleMessage(content)).build()); }
/** * Gets configuration as JSON. * Depends on the log4j core API. * * @param request the request * @param response the response * @return the configuration * @throws Exception the exception */ @GetMapping(value = "/getConfiguration") @ResponseBody public Map<String, Object> getConfiguration(final HttpServletRequest request, final HttpServletResponse response) throws Exception { ensureEndpointAccessIsAuthorized(request, response); Assert.notNull(this.loggerContext); final Collection<Map<String, Object>> configuredLoggers = new HashSet<>(); getLoggerConfigurations().forEach(config -> { final Map<String, Object> loggerMap = new HashMap<>(); loggerMap.put("name", StringUtils.defaultIfBlank(config.getName(), LOGGER_NAME_ROOT)); loggerMap.put("state", config.getState()); if (config.getProperties() != null) { loggerMap.put("properties", config.getProperties()); } loggerMap.put("additive", config.isAdditive()); loggerMap.put("level", config.getLevel().name()); final Collection<String> appenders = new HashSet<>(); config.getAppenders().keySet().stream().map(key -> config.getAppenders().get(key)).forEach(appender -> { final ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.JSON_STYLE); builder.append("name", appender.getName()); builder.append("state", appender.getState()); builder.append("layoutFormat", appender.getLayout().getContentFormat()); builder.append("layoutContentType", appender.getLayout().getContentType()); if (appender instanceof FileAppender) { builder.append(FILE_PARAM, ((FileAppender) appender).getFileName()); builder.append(FILE_PATTERN_PARAM, "(none)"); } if (appender instanceof RandomAccessFileAppender) { builder.append(FILE_PARAM, ((RandomAccessFileAppender) appender).getFileName()); builder.append(FILE_PATTERN_PARAM, "(none)"); } if (appender instanceof RollingFileAppender) { builder.append(FILE_PARAM, ((RollingFileAppender) appender).getFileName()); builder.append(FILE_PATTERN_PARAM, ((RollingFileAppender) appender).getFilePattern()); } if (appender instanceof MemoryMappedFileAppender) { builder.append(FILE_PARAM, ((MemoryMappedFileAppender) appender).getFileName()); builder.append(FILE_PATTERN_PARAM, "(none)"); } if (appender instanceof RollingRandomAccessFileAppender) { builder.append(FILE_PARAM, ((RollingRandomAccessFileAppender) appender).getFileName()); builder.append(FILE_PATTERN_PARAM, ((RollingRandomAccessFileAppender) appender).getFilePattern()); } appenders.add(builder.build()); }); loggerMap.put("appenders", appenders); configuredLoggers.add(loggerMap); }); final Map<String, Object> responseMap = new HashMap<>(); responseMap.put("loggers", configuredLoggers); return responseMap; }
@SuppressWarnings({ "rawtypes", "unchecked" }) public static synchronized void init() { final LoggerContext ctx = (LoggerContext) LogManager.getContext(false); final Configuration config = ctx.getConfiguration(); Layout layout = PatternLayout.newBuilder().withPattern("%d{yyyy-MM-dd HH:mm:ss}:%p %t %c - %m%n") .withConfiguration(config).withRegexReplacement(null).withCharset(null).withAlwaysWriteExceptions(true) .withNoConsoleNoAnsi(false).withHeader(null).withFooter(null).build(); // file info Filter fileInfoFilter = ThresholdFilter.createFilter(Level.ERROR, Result.DENY, Result.ACCEPT); Appender fileInfoAppender = RollingFileAppender.createAppender(LOG_ROOT + "/zebra.log", LOG_ROOT + "/zebra.log.%d{yyyy-MM-dd}.gz", "true", "FileInfo", "true", "4000", "true", TimeBasedTriggeringPolicy.createPolicy("1", "true"), ZebraRolloverStrategy.createStrategy("30", "1", null, Deflater.DEFAULT_COMPRESSION + "", config), layout, fileInfoFilter, "false", null, null, config); config.addAppender(fileInfoAppender); fileInfoAppender.start(); AppenderRef fileInfoRef = AppenderRef.createAppenderRef("FileInfo", null, fileInfoFilter); // console error Appender consoleErrorAppender = ConsoleAppender.createAppender(layout, null, "SYSTEM_ERR", "ConsoleError", "false", "false"); config.addAppender(consoleErrorAppender); consoleErrorAppender.start(); // console info Filter consoleWarnFilter = ThresholdFilter.createFilter(Level.ERROR, Result.DENY, Result.NEUTRAL); Appender consoleWarnAppender = ConsoleAppender.createAppender(layout, consoleWarnFilter, "SYSTEM_OUT", "ConsoleWarn", "false", "false"); config.addAppender(consoleWarnAppender); consoleWarnAppender.start(); AppenderRef consoleWarnAppenderRef = AppenderRef.createAppenderRef("ConsoleWarn", Level.WARN, consoleWarnFilter); AppenderRef consoleErrorAppenderRef = AppenderRef.createAppenderRef("ConsoleError", Level.WARN, null); AppenderRef[] refs = new AppenderRef[] { consoleErrorAppenderRef, consoleWarnAppenderRef, fileInfoRef }; LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, "com.dianping.zebra", "true", refs, null, config, null); loggerConfig.addAppender(consoleErrorAppender, Level.ERROR, null); loggerConfig.addAppender(consoleWarnAppender, Level.INFO, null); loggerConfig.addAppender(fileInfoAppender, Level.INFO, null); config.addLogger("com.dianping.zebra", loggerConfig); ctx.updateLoggers(); context = ctx; }
@Before public void before() { host = context.getListAppender("HostTest").clear(); hostFile = context.getRequiredAppender("HostFile", RollingFileAppender.class); }
/** * Tests https://issues.apache.org/jira/browse/LOG4J2-1620 */ @Test public void testDefaultImmediateFlush() { Assert.assertTrue(RollingFileAppender.newBuilder().isImmediateFlush()); }
private void validateAppender(final LoggerContext loggerContext, final String expectedFilePattern) { final RollingFileAppender appender = loggerContext.getConfiguration().getAppender("fooAppender"); Assert.assertNotNull(appender); Assert.assertEquals(expectedFilePattern, appender.getFilePattern()); LogManager.getLogger("root").info("just to show it works."); }
@Test public void testAppender() throws Exception { // TODO Is there a better way to test than putting the thread to sleep all over the place? final Logger logger = loggerContextRule.getLogger(); final File file = new File(FILE); assertTrue("Log file does not exist", file.exists()); logger.debug("This is test message number 1, waiting for rolling"); final RollingFileAppender app = (RollingFileAppender) loggerContextRule.getLoggerContext().getConfiguration().getAppender("RollingFile"); final TriggeringPolicy policy = app.getManager().getTriggeringPolicy(); assertNotNull("No triggering policy", policy); assertTrue("Incorrect policy type", policy instanceof CronTriggeringPolicy); final CronExpression expression = ((CronTriggeringPolicy) policy).getCronExpression(); assertEquals("Incorrect cron expresion", cronExpression, expression.getCronExpression()); logger.debug("Cron expression will be {}", expression.getCronExpression()); // force a reconfiguration for (int i = 1; i <= 20; ++i) { logger.debug("Adding first event {}", i); } Thread.sleep(remainingTime); final File dir = new File(DIR); assertTrue("Directory not created", dir.exists() && dir.listFiles().length > 0); for (int i = 1; i < 5; i++) { logger.debug("Adding some more event {}", i); Thread.sleep(1000); } final Matcher<File> hasGzippedFile = hasName(that(endsWith(".gz"))); int count = 0; final File[] files = dir.listFiles(); for (final File generatedFile : files) { if (hasGzippedFile.matches(generatedFile)) { count++; } } assertNotEquals("No compressed files found", 0, count); assertEquals("Multiple files found" , 1, count); }