final TriggeringPolicy policy = app.getManager().getTriggeringPolicy(); assertNotNull("No triggering policy", policy); assertTrue("Incorrect policy type", policy instanceof CronTriggeringPolicy);
@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()); }
final TriggeringPolicy policy = app.getManager().getTriggeringPolicy(); assertNotNull("No triggering policy", policy); assertTrue("Incorrect policy type", policy instanceof CronTriggeringPolicy);
/** * 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()); } } }
/** * 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()); } }
/** * Returns the triggering policy. * @param <T> TriggeringPolicy type * @return The TriggeringPolicy */ public <T extends TriggeringPolicy> T getTriggeringPolicy() { return getManager().getTriggeringPolicy(); }
/** * Writes the log entry rolling over the file when required. * @param event The LogEvent. */ @Override public void append(final LogEvent event) { getManager().checkRollover(event); super.append(event); }