use of ch.qos.logback.core.rolling.TimeBasedRollingPolicy 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.TimeBasedRollingPolicy in project TranslateIt-api by zunpiau.
the class LogbackConfigProd method appender.
@Bean(initMethod = "start", destroyMethod = "stop")
public static RollingFileAppender<ILoggingEvent> appender(LoggerContext ctx, PatternLayoutEncoder encoder, @Value("${log.history}") int history, @Value("${log.fileNamePattern}") String parretn) {
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
appender.setContext(ctx);
TimeBasedRollingPolicy rollingPolicy = new TimeBasedRollingPolicy();
rollingPolicy.setMaxHistory(history);
rollingPolicy.setParent(appender);
rollingPolicy.setContext(ctx);
rollingPolicy.setCleanHistoryOnStart(true);
rollingPolicy.setFileNamePattern(parretn);
rollingPolicy.start();
appender.setRollingPolicy(rollingPolicy);
appender.setEncoder(encoder);
return appender;
}
use of ch.qos.logback.core.rolling.TimeBasedRollingPolicy in project cdap-ingest by caskdata.
the class FileTailerIT method getTimeLogger.
private Logger getTimeLogger(String file) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
RollingFileAppender fileAppender = new RollingFileAppender();
fileAppender.setName("File Tailer IT");
fileAppender.setContext(loggerContext);
fileAppender.setFile(file);
fileAppender.setAppend(true);
TimeBasedRollingPolicy rollingPolicy = new TimeBasedRollingPolicy();
rollingPolicy.setContext(loggerContext);
rollingPolicy.setParent(fileAppender);
rollingPolicy.setFileNamePattern(file + "%d{yyyy-MM-dd_HH-mm}");
rollingPolicy.start();
fileAppender.setRollingPolicy(rollingPolicy);
PatternLayoutEncoder layoutEncoder = new PatternLayoutEncoder();
layoutEncoder.setContext(loggerContext);
layoutEncoder.setPattern("%msg%n");
layoutEncoder.start();
fileAppender.setEncoder(layoutEncoder);
fileAppender.start();
// configures the logger
Logger logger = loggerContext.getLogger(FileTailerIT.class.getName() + "time");
logger.setLevel(Level.DEBUG);
logger.addAppender(fileAppender);
return logger;
}
use of ch.qos.logback.core.rolling.TimeBasedRollingPolicy 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.TimeBasedRollingPolicy 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