当前位置: 首页>>代码示例>>Java>>正文


Java ListAppender.clear方法代码示例

本文整理汇总了Java中org.apache.logging.log4j.test.appender.ListAppender.clear方法的典型用法代码示例。如果您正苦于以下问题:Java ListAppender.clear方法的具体用法?Java ListAppender.clear怎么用?Java ListAppender.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.logging.log4j.test.appender.ListAppender的用法示例。


在下文中一共展示了ListAppender.clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testClassName

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
@Test
public void testClassName() {
    final Category category = Category.getInstance("TestCategory");
    final Layout<String> layout = PatternLayout.createLayout("%d %p %C{1.} [%t] %m%n", null, null, null, null);
    final ListAppender appender = new ListAppender("List2", null, layout, false, false);
    appender.start();
    category.setAdditivity(false);
    category.getLogger().addAppender(appender);
    category.error("Test Message");
    final List<String> msgs = appender.getMessages();
    assertTrue("Incorrect number of messages. Expected 1 got " + msgs.size(), msgs.size() == 1);
    final String msg = msgs.get(0);
    appender.clear();
    final String threadName = Thread.currentThread().getName();
    final String expected = "ERROR o.a.l.CategoryTest [" + threadName + "] Test Message" + Constants.LINE_SEP;
    assertTrue("Incorrect message \"" + msg + "\"" + " expected \"" + expected +"\"", msg.endsWith(expected));
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:18,代码来源:CategoryTest.java

示例2: testJavascriptFilter

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
@Test
public void testJavascriptFilter() throws Exception {
    final Logger logger = LogManager.getLogger("TestJavaScriptFilter");
    logger.traceEntry();
    logger.info("This should not be logged");
    ThreadContext.put("UserId", "JohnDoe");
    logger.info("This should be logged");
    ThreadContext.clearMap();
    final ListAppender app = getContext().getListAppender("List");
    final List<String> messages = app.getMessages();
    try {
        assertNotNull("No Messages", messages);
        assertTrue("Incorrect number of messages. Expected 2, Actual " + messages.size(), messages.size() == 2);
    } finally {
        app.clear();
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:18,代码来源:AbstractScriptFilterTest.java

示例3: testGroovyFilter

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
@Test
public void testGroovyFilter() throws Exception {
    final Logger logger = LogManager.getLogger("TestGroovyFilter");
    logger.traceEntry();
    logger.info("This should not be logged");
    ThreadContext.put("UserId", "JohnDoe");
    logger.info("This should be logged");
    ThreadContext.clearMap();
    final ListAppender app = getContext().getListAppender("List");
    try {
        final List<String> messages = app.getMessages();
        assertNotNull("No Messages", messages);
        assertTrue("Incorrect number of messages. Expected 2, Actual " + messages.size(), messages.size() == 2);
    } finally {
        app.clear();
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:18,代码来源:AbstractScriptFilterTest.java

示例4: testLogJsonArgument

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
@Test
public void testLogJsonArgument() throws InterruptedException {
    final ListAppender appender = (ListAppender) init.getAppender("List");
    appender.countDownLatch = new CountDownLatch(4);
    appender.clear();
    final Logger logger = (Logger) LogManager.getRootLogger();
    final String json = "{\"id\":10,\"name\":\"Alice\"}";
    logger.error("log:{}", json);
    // wait until background thread finished processing
    final int msgCount = 1;
    if (appender.getMessages().size() < msgCount) {
        appender.countDownLatch.await(5, TimeUnit.SECONDS);
    }
    assertEquals("Background thread did not finish processing: msg count", msgCount, appender.getMessages().size());

    // don't stop appender until background thread is done
    appender.stop();
    final List<String> list = appender.getMessages();
    final String eventStr = list.get(0).toString();
    Assert.assertTrue(eventStr, eventStr.contains(json));
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:22,代码来源:CsvParameterLayoutTest.java

示例5: testClassName

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
@Test
public void testClassName() {
    final Category category = Category.getInstance("TestCategory");
    final Layout<String> layout = PatternLayout.newBuilder().withPattern("%d %p %C{1.} [%t] %m%n").build();
    final ListAppender appender = new ListAppender("List2", null, layout, false, false);
    appender.start();
    category.setAdditivity(false);
    category.getLogger().addAppender(appender);
    category.error("Test Message");
    final List<String> msgs = appender.getMessages();
    assertTrue("Incorrect number of messages. Expected 1 got " + msgs.size(), msgs.size() == 1);
    final String msg = msgs.get(0);
    appender.clear();
    final String threadName = Thread.currentThread().getName();
    final String expected = "ERROR o.a.l.CategoryTest [" + threadName + "] Test Message" + Strings.LINE_SEPARATOR;
    assertTrue("Incorrect message " + Strings.dquote(msg) + " expected " + Strings.dquote(expected), msg.endsWith(expected));
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:18,代码来源:CategoryTest.java

示例6: testMarkerPatternSelector

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
@Test
public void testMarkerPatternSelector() throws Exception {
    final org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestMarkerPatternSelector");
    logger.traceEntry();
    logger.info("Hello World");
    logger.traceExit();
    final ListAppender app = (ListAppender) context.getRequiredAppender("List");
    assertNotNull("No ListAppender", app);
    final List<String> messages = app.getMessages();
    assertNotNull("No Messages", messages);
    assertTrue("Incorrect number of messages. Expected 3, Actual " + messages.size() + ": " + messages, messages.size() == 3);
    final String expect = String.format("[TRACE] TestMarkerPatternSelector ====== "
            + "o.a.l.l.c.PatternSelectorTest.testMarkerPatternSelector:43 Enter ======%n");
    assertEquals(expect, messages.get(0));
    assertEquals("[INFO ] TestMarkerPatternSelector Hello World" + Strings.LINE_SEPARATOR, messages.get(1));
    app.clear();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:18,代码来源:PatternSelectorTest.java

示例7: testScriptPatternSelector

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
@Test
public void testScriptPatternSelector() throws Exception {
    final org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestScriptPatternSelector");
    final org.apache.logging.log4j.Logger logger2 = LogManager.getLogger("NoLocation");
    logger.traceEntry();
    logger.info("Hello World");
    logger2.info("No location information");
    logger.traceExit();
    final ListAppender app = (ListAppender) context.getRequiredAppender("List2");
    assertNotNull("No ListAppender", app);
    final List<String> messages = app.getMessages();
    assertNotNull("No Messages", messages);
    assertTrue("Incorrect number of messages. Expected 4, Actual " + messages.size() + ": " + messages, messages.size() == 4);
    String expect = "[TRACE] TestScriptPatternSelector ====== " +
            "o.a.l.l.c.PatternSelectorTest.testScriptPatternSelector:62 Enter ======" + Strings.LINE_SEPARATOR;
    assertEquals(expect, messages.get(0));
    expect = "[INFO ] TestScriptPatternSelector o.a.l.l.c.PatternSelectorTest.testScriptPatternSelector.63 " +
            "Hello World" + Strings.LINE_SEPARATOR;
    assertEquals(expect, messages.get(1));
    assertEquals("[INFO ] NoLocation No location information" + Strings.LINE_SEPARATOR, messages.get(2));
    app.clear();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:23,代码来源:PatternSelectorTest.java

示例8: testJavaScriptPatternSelector

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
@Test
public void testJavaScriptPatternSelector() throws Exception {
    final org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestJavaScriptPatternSelector");
    final org.apache.logging.log4j.Logger logger2 = LogManager.getLogger("JavascriptNoLocation");
    logger.traceEntry();
    logger.info("Hello World");
    logger2.info("No location information");
    logger.traceExit();
    final ListAppender app = (ListAppender) context.getRequiredAppender("List3");
    assertNotNull("No ListAppender", app);
    final List<String> messages = app.getMessages();
    assertNotNull("No Messages", messages);
    assertTrue("Incorrect number of messages. Expected 4, Actual " + messages.size() + ": " + messages, messages.size() == 4);
    String expect = "[TRACE] TestJavaScriptPatternSelector ====== " +
            "o.a.l.l.c.PatternSelectorTest.testJavaScriptPatternSelector:85 Enter ======" + Strings.LINE_SEPARATOR;
    assertEquals(expect, messages.get(0));
    expect = "[INFO ] TestJavaScriptPatternSelector " +
            "o.a.l.l.c.PatternSelectorTest.testJavaScriptPatternSelector.86 Hello World" + Strings.LINE_SEPARATOR;
    assertEquals(expect, messages.get(1));
    assertEquals("[INFO ] JavascriptNoLocation No location information" + Strings.LINE_SEPARATOR, messages.get(2));
    app.clear();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:23,代码来源:PatternSelectorTest.java

示例9: before

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
@Before
public void before() {
    config = ctx.getConfiguration();
    for (final Map.Entry<String, Appender> entry : config.getAppenders().entrySet()) {
        if (entry.getKey().equals("List")) {
            app = (ListAppender) entry.getValue();
            break;
        }
    }
    assertNotNull("No Appender", app);
    app.clear();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:13,代码来源:FileConfigTest.java

示例10: before

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
@Before
public void before() {
    config = ctx.getConfiguration();
    for (final Map.Entry<String, Appender> entry : config.getAppenders().entrySet()) {
        if (entry.getKey().equals("List")) {
            app = (ListAppender) entry.getValue();
            break;
        }
    }
    assertNotNull("No Appender", app);
    app.clear();
    ThreadContext.clear();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:14,代码来源:JMSQueueFailoverTest.java

示例11: verify

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
private void verify(final String expected) {
    final ListAppender listApp = context.getListAppender("List");
    final List<String> events = listApp.getMessages();
    try
    {
        assertEquals("Incorrect number of messages.", 1, events.size());
        assertEquals("Incorrect message.", "o.a.l.l.t.CatchingTagTest " + expected, events.get(0));
    }
    finally
    {
        listApp.clear();
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:14,代码来源:CatchingTagTest.java

示例12: verify

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
private void verify(final String expected) {
    final ListAppender listApp = context.getListAppender("List");
    final List<String> events = listApp.getMessages();
    try
    {
        assertEquals("Incorrect number of messages.", 1, events.size());
        assertEquals("Incorrect message.", "o.a.l.l.t.EnterTagTest " + expected, events.get(0));
    }
    finally
    {
        listApp.clear();
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:14,代码来源:EnterTagTest.java

示例13: verify

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
private void verify(final String expected) {
    final ListAppender listApp = context.getListAppender("List");
    final List<String> events = listApp.getMessages();
    try
    {
        assertEquals("Incorrect number of messages.", 1, events.size());
        assertEquals("Incorrect message.", "o.a.l.l.t.LoggingMessageTagSupportTest " + expected, events.get(0));
    }
    finally
    {
        listApp.clear();
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:14,代码来源:LoggingMessageTagSupportTest.java

示例14: testEmptyAttribute

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
@Test
public void testEmptyAttribute() throws Exception {
    final org.apache.logging.log4j.Logger logger = LogManager.getLogger();
    logger.info("msg");

    final ListAppender app = (ListAppender) context.getRequiredAppender("List");
    assertNotNull("No ListAppender", app);

    final List<String> messages = app.getMessages();
    assertNotNull("No Messages", messages);
    assertEquals("message count" + messages, 1, messages.size());

    //<Property name="emptyElementKey" />
    //<Property name="emptyAttributeKey" value="" />
    //<Property name="emptyAttributeKey2" value=""></Property>
    //<Property name="elementKey">elementValue</Property>
    //<Property name="attributeKey" value="attributeValue" />
    //<Property name="attributeWithEmptyElementKey" value="attributeValue2"></Property>
    //<Property name="bothElementAndAttributeKey" value="attributeValue3">elementValue3</Property>
    final String expect = "1=elementValue" + // ${sys:elementKey}
            ",2=" + // ${sys:emptyElementKey}
            ",a=" + // ${sys:emptyAttributeKey}
            ",b=" + // ${sys:emptyAttributeKey2}
            ",3=attributeValue" + // ${sys:attributeKey}
            ",4=attributeValue2" + // ${sys:attributeWithEmptyElementKey}
            ",5=elementValue3,m=msg"; // ${sys:bothElementAndAttributeKey}
    assertEquals(expect, messages.get(0));
    app.clear();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:30,代码来源:PropertyTest.java

示例15: testNoArgBuilderCallerClassInfo

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
@Test
public void testNoArgBuilderCallerClassInfo() throws Exception {
    try (final PrintStream ps = IoBuilder.forLogger().buildPrintStream()) {
        ps.println("discarded");
        final ListAppender app = context.getListAppender("IoBuilderTest");
        final List<String> messages = app.getMessages();
        assertThat(messages, not(empty()));
        assertThat(messages, hasSize(1));
        final String message = messages.get(0);
        assertThat(message, startsWith(getClass().getName() + ".testNoArgBuilderCallerClassInfo"));
        app.clear();
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:14,代码来源:IoBuilderTest.java


注:本文中的org.apache.logging.log4j.test.appender.ListAppender.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。