本文整理汇总了Java中ch.qos.logback.core.read.ListAppender类的典型用法代码示例。如果您正苦于以下问题:Java ListAppender类的具体用法?Java ListAppender怎么用?Java ListAppender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ListAppender类属于ch.qos.logback.core.read包,在下文中一共展示了ListAppender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: workerThreadFlushesOnStop
import ch.qos.logback.core.read.ListAppender; //导入依赖的package包/类
@Test
public void workerThreadFlushesOnStop() {
int loopLen = 5;
int maxRuntime = (loopLen + 1) * Math.max(1000, delayingListAppender.delay);
ListAppender la = delayingListAppender;
asyncAppenderBase.addAppender(la);
asyncAppenderBase.setDiscardingThreshold(0);
asyncAppenderBase.setMaxFlushTime(maxRuntime);
asyncAppenderBase.start();
asyncAppenderBase.worker.suspend();
for (int i = 0; i < loopLen; i++) {
asyncAppenderBase.doAppend(i);
}
assertEquals(loopLen, asyncAppenderBase.getNumberOfElementsInQueue());
assertEquals(0, la.list.size());
asyncAppenderBase.worker.resume();
asyncAppenderBase.stop();
assertEquals(0, asyncAppenderBase.getNumberOfElementsInQueue());
verify(la, loopLen);
}
示例2: testLevelFilter
import ch.qos.logback.core.read.ListAppender; //导入依赖的package包/类
@Test
public void testLevelFilter() throws JoranException {
configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "levelFilter.xml");
// StatusPrinter.print(loggerContext);
logger.warn("hello");
logger.error("to be ignored");
@SuppressWarnings("unchecked")
ListAppender<ILoggingEvent> listAppender = (ListAppender) root
.getAppender("LIST");
assertNotNull(listAppender);
assertEquals(1, listAppender.list.size());
ILoggingEvent back = listAppender.list.get(0);
assertEquals(Level.WARN, back.getLevel());
assertEquals("hello", back.getMessage());
}
示例3: testEvaluatorFilter
import ch.qos.logback.core.read.ListAppender; //导入依赖的package包/类
@Test
public void testEvaluatorFilter() throws JoranException {
configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "evaluatorFilter.xml");
// StatusPrinter.print(loggerContext);
logger.warn("hello");
logger.error("to be ignored");
@SuppressWarnings("unchecked")
ListAppender<ILoggingEvent> listAppender = (ListAppender) root
.getAppender("LIST");
assertNotNull(listAppender);
assertEquals(1, listAppender.list.size());
ILoggingEvent back = listAppender.list.get(0);
assertEquals(Level.WARN, back.getLevel());
assertEquals("hello", back.getMessage());
}
示例4: testTurboDynamicThreshold
import ch.qos.logback.core.read.ListAppender; //导入依赖的package包/类
@Test
public void testTurboDynamicThreshold() throws JoranException {
configure(ClassicTestConstants.JORAN_INPUT_PREFIX
+ "turboDynamicThreshold.xml");
ListAppender listAppender = (ListAppender) root.getAppender("LIST");
assertEquals(0, listAppender.list.size());
// this one should be denied
MDC.put("userId", "user1");
logger.debug("hello user1");
// this one should log
MDC.put("userId", "user2");
logger.debug("hello user2");
assertEquals(1, listAppender.list.size());
ILoggingEvent le = (ILoggingEvent) listAppender.list.get(0);
assertEquals("hello user2", le.getMessage());
}
示例5: testTurboDynamicThreshold2
import ch.qos.logback.core.read.ListAppender; //导入依赖的package包/类
@Test
public void testTurboDynamicThreshold2() throws JoranException {
configure(ClassicTestConstants.JORAN_INPUT_PREFIX
+ "turboDynamicThreshold2.xml");
ListAppender listAppender = (ListAppender) root.getAppender("LIST");
assertEquals(0, listAppender.list.size());
// this one should log
MDC.put("userId", "user1");
logger.debug("hello user1");
// this one should log
MDC.put("userId", "user2");
logger.debug("hello user2");
// this one should fail
MDC.put("userId", "user3");
logger.debug("hello user3");
assertEquals(2, listAppender.list.size());
ILoggingEvent le = (ILoggingEvent) listAppender.list.get(0);
assertEquals("hello user1", le.getMessage());
le = (ILoggingEvent) listAppender.list.get(1);
assertEquals("hello user2", le.getMessage());
}
示例6: conditionalConsoleApp_IF_THEN_ELSE
import ch.qos.logback.core.read.ListAppender; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Test
public void conditionalConsoleApp_IF_THEN_ELSE() throws JoranException,
IOException, InterruptedException {
String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX
+ "conditional/conditionalConsoleApp_ELSE.xml";
configure(configFileAsStr);
FileAppender fileAppender = (FileAppender) root.getAppender("FILE");
assertNotNull(fileAppender);
ConsoleAppender consoleAppender = (ConsoleAppender) root.getAppender("CON");
assertNull(consoleAppender);
ListAppender listAppender = (ListAppender) root.getAppender("LIST");
assertNotNull(listAppender);
// StatusPrinter.printIfErrorsOccured(context);
StatusChecker checker = new StatusChecker(context);
checker.assertIsErrorFree();
}
示例7: testWholeCycle
import ch.qos.logback.core.read.ListAppender; //导入依赖的package包/类
@Test
public void testWholeCycle() throws JoranException {
String mdcKey = "cycle";
configure(SIFT_FOLDER_PREFIX + "completeCycle.xml");
MDC.put(mdcKey, "a");
logger.debug("smoke");
long timestamp = System.currentTimeMillis();
SiftingAppender sa = (SiftingAppender) root.getAppender("SIFT");
ListAppender<ILoggingEvent> listAppender = (ListAppender<ILoggingEvent>)
sa.getAppenderTracker().find("a");
assertNotNull(listAppender);
List<ILoggingEvent> eventList = listAppender.list;
assertEquals(1, listAppender.list.size());
assertEquals("smoke", eventList.get(0).getMessage());
MDC.remove(mdcKey);
LoggingEvent le = new LoggingEvent("x", logger, Level.INFO, "hello", null,
null);
le.setTimeStamp(timestamp + ComponentTracker.DEFAULT_TIMEOUT + 1);
sa.doAppend(le);
assertFalse(listAppender.isStarted());
assertEquals(1, sa.getAppenderTracker().allKeys().size());
assertTrue(sa.getAppenderTracker().allKeys().contains("cycleDefault"));
}
示例8: QueueMessageHandler
import ch.qos.logback.core.read.ListAppender; //导入依赖的package包/类
@Test
public void getMappingForMethod_methodWithDeletionPolicyNeverWithoutParameterTypeAcknowledgment_warningMustBeLogged() throws Exception {
// Arrange
QueueMessageHandler queueMessageHandler = new QueueMessageHandler();
Method receiveMethod = SqsListenerDeletionPolicyNeverNoAcknowledgment.class.getMethod("receive", String.class);
LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory();
ListAppender<ILoggingEvent> appender = new ListAppender<>();
appender.start();
Logger log = logContext.getLogger(QueueMessageHandler.class);
log.setLevel(Level.WARN);
log.addAppender(appender);
appender.setContext(log.getLoggerContext());
// Act
queueMessageHandler.getMappingForMethod(receiveMethod, null);
// Assert
ILoggingEvent loggingEvent = appender.list.get(0);
assertSame(Level.WARN, loggingEvent.getLevel());
assertTrue(loggingEvent.getMessage().contains("receive"));
assertTrue(loggingEvent.getMessage().contains("org.springframework.cloud.aws.messaging.listener.QueueMessageHandlerTest$SqsListenerDeletionPolicyNeverNoAcknowledgment"));
}
示例9: matches
import ch.qos.logback.core.read.ListAppender; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public boolean matches(Object actual) {
if (actual instanceof LogbackJUnitRule) {
LogbackJUnitRule rule = (LogbackJUnitRule) actual;
if (matches(rule.capture())) {
return true;
}
}
if (actual instanceof ListAppender) {
ListAppender<ILoggingEvent> appender = (ListAppender<ILoggingEvent>) actual;
if (matches(appender.list)) {
return true;
}
}
if (actual instanceof List) {
return matches((List<ILoggingEvent>) actual);
}
if (actual instanceof ILoggingEvent) {
return matches((ILoggingEvent) actual);
}
return false;
}
示例10: matches
import ch.qos.logback.core.read.ListAppender; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public boolean matches(Object actual) {
if(!initalized) {
init();
initalized = true;
}
if (actual instanceof LogbackJUnitRule) {
LogbackJUnitRule rule = (LogbackJUnitRule) actual;
if (matches(rule.capture())) {
return true;
}
}
if (actual instanceof ListAppender) {
ListAppender<ILoggingEvent> appender = (ListAppender<ILoggingEvent>) actual;
if (matches(appender.list)) {
return true;
}
}
if (actual instanceof List) {
return matches((List<ILoggingEvent>) actual);
}
if (actual instanceof ILoggingEvent) {
return matches((ILoggingEvent) actual);
}
return false;
}
示例11: matches
import ch.qos.logback.core.read.ListAppender; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public boolean matches(Object actual) {
if(actual instanceof LogbackJUnitRule) {
LogbackJUnitRule rule = (LogbackJUnitRule)actual;
if(matches(rule.capture())) {
return true;
}
}
if(actual instanceof ListAppender) {
ListAppender<ILoggingEvent> appender = (ListAppender<ILoggingEvent>)actual;
if(matches(appender.list)) {
return true;
}
}
if(actual instanceof List) {
return matches((List<ILoggingEvent>)actual);
}
if(actual instanceof ILoggingEvent) {
return matches((ILoggingEvent)actual);
}
return false;
}
示例12: testConfigurationMissingFileLogsWarning
import ch.qos.logback.core.read.ListAppender; //导入依赖的package包/类
@Test
public void testConfigurationMissingFileLogsWarning() throws Exception {
final Map<String, String> configProperties = new HashMap<String, String>();
configProperties.put(FileIdentityProvider.PROPERTY_EXPIRATION_PERIOD, FIVE_MINUTES);
final String missingFilePath = "no/such/file";
configProperties.put(FileIdentityProvider.PROPERTY_CREDENTIALS_FILE, missingFilePath);
final LoginIdentityProviderConfigurationContext configContext =
new MockLoginIdentityProviderConfigurationContext(IDENTIFIER, configProperties);
Logger fileIdentityProviderLogger = (Logger) LoggerFactory.getLogger(FileIdentityProvider.class);
ListAppender<ILoggingEvent> testAppender = new ListAppender<>();
testAppender.setName("Test");
testAppender.start();
fileIdentityProviderLogger.addAppender(testAppender);
final FileIdentityProvider provider = new FileIdentityProvider();
provider.onConfigured(configContext);
boolean fileMessageFound = false;
for (ILoggingEvent event : testAppender.list) {
String message = event.getFormattedMessage();
if (message.contains(missingFilePath) && event.getLevel() == Level.WARN) {
fileMessageFound = true;
break;
}
}
Assert.assertTrue(fileMessageFound);
}
示例13: setUp
import ch.qos.logback.core.read.ListAppender; //导入依赖的package包/类
@Before
public void setUp() {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
setListAppender(new ListAppender<>());
setFilter(new ThresholdFilter());
setLogThreshold(Level.WARN);
getFilter().start();
getListAppender().addFilter(getFilter());
getListAppender().start();
root.addAppender(getListAppender());
}
示例14: stopExitsWhenMaxRuntimeReached
import ch.qos.logback.core.read.ListAppender; //导入依赖的package包/类
@Test
public void stopExitsWhenMaxRuntimeReached() throws InterruptedException {
int maxRuntime = 1; //runtime of 0 means wait forever, so use 1 ms instead
int loopLen = 10;
ListAppender la = delayingListAppender;
asyncAppenderBase.addAppender(la);
asyncAppenderBase.setMaxFlushTime(maxRuntime);
asyncAppenderBase.start();
for (int i = 0; i < loopLen; i++) {
asyncAppenderBase.doAppend(i);
}
asyncAppenderBase.stop();
//suspend the thread so that we can make the following assertions without race conditions
asyncAppenderBase.worker.suspend();
//confirms that stop exited when runtime reached
statusChecker.assertContainsMatch("Max queue flush timeout \\(" + maxRuntime + " ms\\) exceeded.");
//confirms that the number of events posted are the number of events removed from the queue
assertEquals(la.list.size(), loopLen - asyncAppenderBase.getNumberOfElementsInQueue());
//resume the thread to let it finish processing
asyncAppenderBase.worker.resume();
asyncAppenderBase.worker.join();
//confirms that all entries do end up being flushed if we wait long enough
verify(la, loopLen);
}
示例15: buildAppender
import ch.qos.logback.core.read.ListAppender; //导入依赖的package包/类
public Appender<Object> buildAppender(Context context, String discriminatingValue) throws JoranException {
ListAppender<Object> la = new ListAppender<Object>();
la.setContext(context);
la.setName(discriminatingValue);
la.start();
return la;
}