use of ch.qos.logback.core.rolling.RollingPolicy in project qpid-broker-j by apache.
the class AppenderUtilsTest method testCreateRollingFileAppenderNonDailyRolling.
public void testCreateRollingFileAppenderNonDailyRolling() {
when(_settings.isRollDaily()).thenReturn(Boolean.FALSE);
when(_settings.isCompressOldFiles()).thenReturn(Boolean.FALSE);
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
AppenderUtils.configureRollingFileAppender(_settings, new LoggerContext(), appender);
assertEquals("Unexpected appender file name", _testLogFileName, appender.getFile());
RollingPolicy rollingPolicy = appender.getRollingPolicy();
assertTrue("Unexpected rolling policy", rollingPolicy instanceof RollingPolicyDecorator);
rollingPolicy = ((RollingPolicyDecorator) rollingPolicy).getDecorated();
assertTrue("Unexpected decorated rolling policy", rollingPolicy instanceof AppenderUtils.SimpleRollingPolicy);
assertEquals("Unexpected max history", MAX_HISTORY, ((AppenderUtils.SimpleRollingPolicy) rollingPolicy).getMaxIndex());
assertEquals("Unexpected file name pattern", _testLogFileName + ".%i", ((AppenderUtils.SimpleRollingPolicy) rollingPolicy).getFileNamePattern());
assertEquals("Unexpected compression mode", CompressionMode.NONE, rollingPolicy.getCompressionMode());
TriggeringPolicy triggeringPolicy = appender.getTriggeringPolicy();
assertEquals("Unexpected triggering policy", String.valueOf(MAX_FILE_SIZE) + " MB", ((AppenderUtils.SizeTriggeringPolicy) triggeringPolicy).getMaxFileSize().toString());
Encoder encoder = appender.getEncoder();
assertTrue("Unexpected encoder", encoder instanceof PatternLayoutEncoder);
assertEquals("Unexpected layout pattern", LAYOUT, ((PatternLayoutEncoder) encoder).getPattern());
}
use of ch.qos.logback.core.rolling.RollingPolicy in project coffeenet-starter by coffeenet.
the class CoffeeNetLoggingAutoConfigurationTest method integration.
@Test
public void integration() {
final Logger logger = (Logger) LoggerFactory.getLogger(ROOT_LOGGER_NAME);
assertThat(logger.getAppender("CONSOLE"), is(instanceOf(ConsoleAppender.class)));
Appender<ILoggingEvent> fileAppender = logger.getAppender("COFFEENET-FILE");
assertThat(fileAppender, is(instanceOf(RollingFileAppender.class)));
// Check File Appender
RollingFileAppender rollingFileAppender = (RollingFileAppender) fileAppender;
assertThat(rollingFileAppender.getFile(), is("logs/app.log"));
assertThat(rollingFileAppender.getName(), is("COFFEENET-FILE"));
RollingPolicy rollingPolicy = rollingFileAppender.getRollingPolicy();
assertThat(rollingPolicy, is(instanceOf(TimeBasedRollingPolicy.class)));
TimeBasedRollingPolicy timeBasedRollingPolicy = (TimeBasedRollingPolicy) rollingFileAppender.getRollingPolicy();
assertThat(timeBasedRollingPolicy.getFileNamePattern(), is("logs/app-%d{yyyy-MM-dd}.log"));
PatternLayoutEncoder encoder = (PatternLayoutEncoder) rollingFileAppender.getEncoder();
assertThat(encoder.getPattern(), is("%d{yyyy-MM-dd HH:mm:ss.SSS} %5p --- [%t] %-40.40logger{39} : %m%n%wEx"));
// Check Gelf Appender
Appender<ILoggingEvent> gelfAppender = logger.getAppender("COFFEENET-GELF");
assertThat(gelfAppender, is(instanceOf(GelfAppender.class)));
GelfAppender gelfAppender1 = (GelfAppender) gelfAppender;
assertThat(gelfAppender1.getName(), is("COFFEENET-GELF"));
assertThat(gelfAppender1.getServer(), is("localServer"));
assertThat(gelfAppender1.getProtocol(), is("TCP"));
assertThat(gelfAppender1.getPort(), is(1337));
assertThat(((PatternLayout) gelfAppender1.getLayout()).getPattern(), is("%m"));
assertThat(gelfAppender1.getAdditionalFields(), hasEntry("environment", "test"));
assertThat(gelfAppender1.getAdditionalFields(), hasEntry("application", "CoffeeNetApplication"));
}
use of ch.qos.logback.core.rolling.RollingPolicy in project coffeenet-starter by coffeenet.
the class CoffeeNetLoggingAutoConfigurationTest method integration.
@Test
public void integration() {
final Logger logger = (Logger) LoggerFactory.getLogger(ROOT_LOGGER_NAME);
assertThat(logger.getAppender("CONSOLE"), is(instanceOf(ConsoleAppender.class)));
Appender<ILoggingEvent> fileAppender = logger.getAppender("COFFEENET-FILE");
assertThat(fileAppender, is(instanceOf(RollingFileAppender.class)));
// Check File Appender
RollingFileAppender rollingFileAppender = (RollingFileAppender) fileAppender;
assertThat(rollingFileAppender.getFile(), is("logs/app.log"));
assertThat(rollingFileAppender.getName(), is("COFFEENET-FILE"));
RollingPolicy rollingPolicy = rollingFileAppender.getRollingPolicy();
assertThat(rollingPolicy, is(instanceOf(TimeBasedRollingPolicy.class)));
TimeBasedRollingPolicy timeBasedRollingPolicy = (TimeBasedRollingPolicy) rollingFileAppender.getRollingPolicy();
assertThat(timeBasedRollingPolicy.getFileNamePattern(), is("logs/app-%d{yyyy-MM-dd}.log"));
PatternLayoutEncoder encoder = (PatternLayoutEncoder) rollingFileAppender.getEncoder();
assertThat(encoder.getPattern(), is("%d{yyyy-MM-dd HH:mm:ss.SSS} %5p --- [%t] %-40.40logger{39} : %m%n%wEx"));
// Check Gelf Appender
Appender<ILoggingEvent> gelfAppender = logger.getAppender("COFFEENET-GELF");
assertThat(gelfAppender, is(instanceOf(GelfAppender.class)));
GelfAppender gelfAppender1 = (GelfAppender) gelfAppender;
assertThat(gelfAppender1.getName(), is("COFFEENET-GELF"));
assertThat(gelfAppender1.getServer(), is("localServer"));
assertThat(gelfAppender1.getProtocol(), is("TCP"));
assertThat(gelfAppender1.getPort(), is(1337));
assertThat(((PatternLayout) gelfAppender1.getLayout()).getPattern(), is("%m"));
assertThat(gelfAppender1.getAdditionalFields(), hasEntry("environment", "test"));
assertThat(gelfAppender1.getAdditionalFields(), hasEntry("application", "CoffeeNetApplication"));
}
use of ch.qos.logback.core.rolling.RollingPolicy in project spring-boot by spring-projects.
the class LogbackConfigurationTests method defaultRollingFileNamePattern.
@Test
void defaultRollingFileNamePattern() throws JoranException {
JoranConfigurator configurator = new JoranConfigurator();
LoggerContext context = new LoggerContext();
configurator.setContext(context);
configurator.doConfigure(new File("src/test/resources/custom-file-log-pattern.xml"));
Appender<ILoggingEvent> appender = context.getLogger("ROOT").getAppender("FILE");
assertThat(appender).isInstanceOf(RollingFileAppender.class);
RollingPolicy rollingPolicy = ((RollingFileAppender<?>) appender).getRollingPolicy();
String fileNamePattern = ((SizeAndTimeBasedRollingPolicy<?>) rollingPolicy).getFileNamePattern();
assertThat(fileNamePattern).endsWith("spring.log.%d{yyyy-MM-dd}.%i.gz");
}
use of ch.qos.logback.core.rolling.RollingPolicy in project midpoint by Evolveum.
the class TestLoggingConfiguration method test110SetMaxHistory.
// MID-5674
@Test
public void test110SetMaxHistory() throws Exception {
// GIVEN
Task task = taskManager.createTaskInstance(TestLoggingConfiguration.class.getName() + ".test101EnableBasicAudit");
OperationResult result = task.getResult();
// Setup
PrismObject<SystemConfigurationType> systemConfiguration = PrismTestUtil.parseObject(AbstractInitializedModelIntegrationTest.SYSTEM_CONFIGURATION_FILE);
LoggingConfigurationType logging = systemConfiguration.asObjectable().getLogging();
applyTestLoggingConfig(logging);
((FileAppenderConfigurationType) logging.getAppender().get(0)).setMaxHistory(100);
Collection<ObjectDelta<? extends ObjectType>> deltas = cast(prismContext.deltaFor(SystemConfigurationType.class).item(SystemConfigurationType.F_LOGGING).replace(logging.asPrismContainerValue().clone()).asObjectDeltas(AbstractInitializedModelIntegrationTest.SYSTEM_CONFIGURATION_OID));
// WHEN
modelService.executeChanges(deltas, null, task, result);
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger logger = context.getLogger(Logger.ROOT_LOGGER_NAME);
assertNotNull("No logger", logger);
Iterator<Appender<ILoggingEvent>> appenderIterator = logger.iteratorForAppenders();
RollingFileAppender<ILoggingEvent> fileAppender = null;
while (appenderIterator.hasNext()) {
Appender<ILoggingEvent> appender = appenderIterator.next();
System.out.println("Appender: " + appender);
if (appender instanceof RollingFileAppender) {
fileAppender = (RollingFileAppender<ILoggingEvent>) appender;
break;
}
}
assertNotNull("No file appender", fileAppender);
RollingPolicy rollingPolicy = fileAppender.getRollingPolicy();
System.out.println("Rolling policy = " + rollingPolicy);
assertTrue("Wrong type of rolling policy", rollingPolicy instanceof TimeBasedRollingPolicy);
TimeBasedRollingPolicy<?> timeBasedRollingPolicy = (TimeBasedRollingPolicy<?>) rollingPolicy;
assertEquals("Wrong maxHistory", 100, timeBasedRollingPolicy.getMaxHistory());
}
Aggregations