use of ch.qos.logback.classic.spi.ILoggingEvent in project dropwizard by dropwizard.
the class FileAppenderFactoryTest method isRolling.
@Test
public void isRolling() throws Exception {
// the method we want to test is protected, so we need to override it so we can see it
FileAppenderFactory fileAppenderFactory = new FileAppenderFactory<ILoggingEvent>() {
@Override
public FileAppender<ILoggingEvent> buildAppender(LoggerContext context) {
return super.buildAppender(context);
}
};
fileAppenderFactory.setCurrentLogFilename(folder.newFile("logfile.log").toString());
fileAppenderFactory.setArchive(true);
fileAppenderFactory.setArchivedLogFilenamePattern(folder.newFile("example-%d.log.gz").toString());
assertThat(fileAppenderFactory.buildAppender(new LoggerContext())).isInstanceOf(RollingFileAppender.class);
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project dropwizard by dropwizard.
the class FileAppenderFactoryTest method testCurrentLogFileNameIsEmptyAndAppenderUsesArchivedNameInstead.
@Test
public void testCurrentLogFileNameIsEmptyAndAppenderUsesArchivedNameInstead() throws Exception {
final FileAppenderFactory<ILoggingEvent> appenderFactory = new FileAppenderFactory<>();
appenderFactory.setArchivedLogFilenamePattern(folder.newFile("test-archived-name-%d.log").toString());
final FileAppender<ILoggingEvent> rollingAppender = appenderFactory.buildAppender(new LoggerContext());
final String file = rollingAppender.getFile();
final String dateSuffix = LocalDateTime.now().format(DateTimeFormatter.ofPattern("YYYY-MM-dd"));
final String name = Files.getNameWithoutExtension(file);
Assert.assertEquals("test-archived-name-" + dateSuffix, name);
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project openhab1-addons by openhab.
the class LoggingPersistenceService method createNewAppender.
protected FileAppender<ILoggingEvent> createNewAppender(String alias) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(context);
encoder.setPattern(pattern);
encoder.start();
FileAppender<ILoggingEvent> appender = new FileAppender<ILoggingEvent>();
appender.setAppend(true);
appender.setFile(LOG_FOLDER + File.separator + alias + LOG_FILEEXT);
appender.setEncoder(encoder);
appender.setContext(context);
appender.start();
return appender;
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project jackrabbit-oak by apache.
the class OperationLoggerTest method testBinaryLogger.
public void testBinaryLogger() throws Exception {
Node node1 = testRootNode.addNode(nodeName1);
start();
byte[] data = "hello".getBytes();
Binary b = superuser.getValueFactory().createBinary(new ByteArrayInputStream(data));
node1.setProperty("foo", b);
stop();
boolean binaryLog = false;
for (ILoggingEvent e : logs.list) {
if (e.getLoggerName().startsWith(OPS_BINARY)) {
if (e.getMessage().contains("Created binary property")) {
assertEquals(Long.valueOf(data.length), e.getArgumentArray()[0]);
binaryLog = true;
}
}
}
assertTrue("Did not find binary upload log", binaryLog);
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project sling by apache.
the class ITFilterSupport method filterUsingWildcard.
@Test
public void filterUsingWildcard() throws Exception {
TestAppender ta1 = registerAppender("filterUsingWildcard1", "app1");
TestAppender ta2 = registerAppender("filterUsingWildcard2", "app2");
//Set additivity to false to prevent other appender like CONSOLE from
//interfering
org.slf4j.Logger baz1 = LoggerFactory.getLogger("filterUsingWildcard1.foo.baz");
((ch.qos.logback.classic.Logger) baz1).setAdditive(false);
org.slf4j.Logger baz2 = LoggerFactory.getLogger("filterUsingWildcard2.foo.baz");
((ch.qos.logback.classic.Logger) baz2).setAdditive(false);
final List<String> msgs = new ArrayList<String>();
Filter stf = new Filter<ILoggingEvent>() {
@Override
public FilterReply decide(ILoggingEvent event) {
msgs.add(event.getMessage());
return FilterReply.NEUTRAL;
}
};
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put("appenders", "*");
ServiceRegistration sr = bundleContext.registerService(Filter.class.getName(), stf, props);
delay();
baz1.info("baz1-1");
baz2.info("baz2-1");
assertEquals(2, msgs.size());
}
Aggregations