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


Java ListAppender.getEvents方法代码示例

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


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

示例1: testTrace

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
/**
 * Tests logger.trace(Object).
 */
@Test
public void testTrace() {
    final ListAppender appender = new ListAppender("List");
    appender.start();
    final Logger root = Logger.getRootLogger();
    root.getLogger().addAppender(appender);
    root.setLevel(Level.INFO);

    final Logger tracer = Logger.getLogger("com.example.Tracer");
    tracer.setLevel(Level.TRACE);

    tracer.trace("Message 1");
    root.trace("Discarded Message");
    root.trace("Discarded Message");

    final List<LogEvent> msgs = appender.getEvents();
    assertEquals(1, msgs.size());
    final LogEvent event = msgs.get(0);
    assertEquals(org.apache.logging.log4j.Level.TRACE, event.getLevel());
    assertEquals("Message 1", event.getMessage().getFormat());
    appender.stop();
    root.getLogger().removeAppender(appender);
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:27,代码来源:LoggerTest.java

示例2: testTraceWithException

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
/**
 * Tests logger.trace(Object, Exception).
 */
@Test
public void testTraceWithException() {
    final ListAppender appender = new ListAppender("List");
    appender.start();
    final Logger root = Logger.getRootLogger();
    root.getLogger().addAppender(appender);
    root.setLevel(Level.INFO);

    final Logger tracer = Logger.getLogger("com.example.Tracer");
    tracer.setLevel(Level.TRACE);
    final NullPointerException ex = new NullPointerException();

    tracer.trace("Message 1", ex);
    root.trace("Discarded Message", ex);
    root.trace("Discarded Message", ex);

    final List<LogEvent> msgs = appender.getEvents();
    assertEquals(1, msgs.size());
    final LogEvent event = msgs.get(0);
    assertEquals(org.apache.logging.log4j.Level.TRACE, event.getLevel());
    assertEquals("Message 1", event.getMessage().getFormattedMessage());
    appender.stop();
    root.getLogger().removeAppender(appender);
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:28,代码来源:LoggerTest.java

示例3: testServer

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
protected void testServer(final String message1, final String message2) throws Exception {
    final Filter socketFilter = new ThreadFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
    final Filter serverFilter = new ThreadFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
    final SocketAppender appender = SocketAppender.createAppender("localhost", this.port, this.protocol, "-1", null, "Test", null,
            "false", null, socketFilter, null, null);
    appender.start();
    final ListAppender listApp = new ListAppender("Events", serverFilter, null, false, false);
    listApp.start();
    final PatternLayout layout = PatternLayout.createLayout("%m %ex%n", null, null, null, null);
    final ConsoleAppender console = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
    final Logger serverLogger = ctx.getLogger(this.getClass().getName());
    serverLogger.addAppender(console);
    serverLogger.setAdditive(false);

    // set appender on root and set level to debug
    root.addAppender(appender);
    root.addAppender(listApp);
    root.setAdditive(false);
    root.setLevel(Level.DEBUG);
    root.debug(message1);
    root.debug(message2);
    Thread.sleep(100);
    final List<LogEvent> events = listApp.getEvents();
    assertNotNull("No event retrieved", events);
    assertTrue("No events retrieved", events.size() > 0);
    assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals(message1));
    assertTrue("Incorrect number of events received: " + events.size(), events.size() == 2);
    assertTrue("Incorrect event", events.get(1).getMessage().getFormattedMessage().equals(message2));
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:30,代码来源:AbstractSocketServerTest.java

示例4: testServer

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
@Test
public void testServer() throws Exception {
    final Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
    final Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
    final CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
    final JMSQueueAppender appender = JMSQueueAppender.createAppender("Test", null, null, null, null, null, FACTORY_NAME,
            QUEUE_NAME, null, null, null, clientFilters, "true");
    appender.start();
    final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
    final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
    listApp.start();
    final PatternLayout layout = PatternLayout.createLayout("%m %ex%n", null, null, null, null);
    final ConsoleAppender console = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
    console.start();
    final Logger serverLogger = ctx.getLogger(JMSTopicReceiver.class.getName());
    serverLogger.addAppender(console);
    serverLogger.setAdditive(false);


    // set appender on root and set level to debug
    root.addAppender(listApp);
    root.addAppender(appender);
    root.setAdditive(false);
    root.setLevel(Level.DEBUG);
    root.debug("This is a test message");
    Thread.sleep(100);
    final List<LogEvent> events = listApp.getEvents();
    assertNotNull("No event retrieved", events);
    assertTrue("No events retrieved", events.size() > 0);
    assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals("This is a test message"));
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:32,代码来源:JMSQueueTest.java

示例5: testServer

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
@Test
public void testServer() throws Exception {
    final Filter clientFilter = new MessageFilter(Filter.Result.NEUTRAL, Filter.Result.DENY);
    final Filter serverFilter = new MessageFilter(Filter.Result.DENY, Filter.Result.NEUTRAL);
    final CompositeFilter clientFilters = CompositeFilter.createFilters(new Filter[]{clientFilter});
    final JMSTopicAppender appender = JMSTopicAppender.createAppender("Test", null, null, null, null, null, FACTORY_NAME,
            TOPIC_NAME, null, null, null, clientFilters, "true");
    appender.start();
    final CompositeFilter serverFilters = CompositeFilter.createFilters(new Filter[]{serverFilter});
    final ListAppender listApp = new ListAppender("Events", serverFilters, null, false, false);
    listApp.start();
    final PatternLayout layout = PatternLayout.createLayout("%m %ex%n", null, null, null, null);
    final ConsoleAppender console =
            ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
    console.start();
    final Logger serverLogger = ctx.getLogger(JMSTopicReceiver.class.getName());
    serverLogger.addAppender(console);
    serverLogger.setAdditive(false);


    // set appender on root and set level to debug
    root.addAppender(listApp);
    root.addAppender(appender);
    root.setAdditive(false);
    root.setLevel(Level.DEBUG);
    root.debug("This is a test message");
    Thread.sleep(100);
    final List<LogEvent> events = listApp.getEvents();
    assertNotNull("No event retrieved", events);
    assertTrue("No events retrieved", events.size() > 0);
    assertTrue("Incorrect event", events.get(0).getMessage().getFormattedMessage().equals("This is a test message"));
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:33,代码来源:JMSTopicTest.java

示例6: testTraceWithException

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
/**
 * Tests logger.trace(Object, Exception).
 */
@Test
public void testTraceWithException() {
    final ListAppender appender = new ListAppender("List");
    appender.start();
    final Logger root = Logger.getRootLogger();
    try {
        root.getLogger().addAppender(appender);
        root.setLevel(Level.INFO);

        final Logger tracer = Logger.getLogger("com.example.Tracer");
        tracer.setLevel(Level.TRACE);
        final NullPointerException ex = new NullPointerException();

        tracer.trace("Message 1", ex);
        root.trace("Discarded Message", ex);
        root.trace("Discarded Message", ex);

        final List<LogEvent> msgs = appender.getEvents();
        assertEquals(1, msgs.size());
        final LogEvent event = msgs.get(0);
        assertEquals(org.apache.logging.log4j.Level.TRACE, event.getLevel());
        assertEquals("Message 1", event.getMessage().getFormattedMessage());
        appender.stop();
    } finally {
        root.getLogger().removeAppender(appender);
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:31,代码来源:LoggerTest.java

示例7: logAndCheck

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
private void logAndCheck() {
    final Marker marker = MarkerManager.getMarker("HEXDUMP");
    final Logger logger = loggerContextRule.getLogger(DefaultRouteScriptAppenderTest.class);
    logger.error("Hello");
    final ListAppender listAppender = getListAppender();
    final List<LogEvent> list = listAppender.getEvents();
    assertNotNull("No events generated", list);
    assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size() == 1);
    logger.error("World");
    assertTrue("Incorrect number of events. Expected 2, got " + list.size(), list.size() == 2);
    logger.error(marker, "DEADBEEF");
    assertTrue("Incorrect number of events. Expected 3, got " + list.size(), list.size() == 3);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:14,代码来源:DefaultRouteScriptAppenderTest.java

示例8: logAndCheck

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
private void logAndCheck() {
    final Marker marker = MarkerManager.getMarker("HEXDUMP");
    final Logger logger = loggerContextRule.getLogger(RoutesScriptAppenderTest.class);
    logger.error("Hello");
    final ListAppender listAppender = getListAppender();
    final List<LogEvent> list = listAppender.getEvents();
    assertNotNull("No events generated", list);
    assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size() == 1);
    logger.error("World");
    assertTrue("Incorrect number of events. Expected 2, got " + list.size(), list.size() == 2);
    logger.error(marker, "DEADBEEF");
    assertTrue("Incorrect number of events. Expected 3, got " + list.size(), list.size() == 3);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:14,代码来源:RoutesScriptAppenderTest.java

示例9: logAndCheck

import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
private void logAndCheck() {
    final Marker marker = MarkerManager.getMarker("HEXDUMP");
    final Logger logger = loggerContextRule.getLogger(ScriptAppenderSelectorTest.class);
    logger.error("Hello");
    final ListAppender listAppender = getListAppender();
    final List<LogEvent> list = listAppender.getEvents();
    assertNotNull("No events generated", list);
    assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size() == 1);
    logger.error("World");
    assertTrue("Incorrect number of events. Expected 2, got " + list.size(), list.size() == 2);
    logger.error(marker, "DEADBEEF");
    assertTrue("Incorrect number of events. Expected 3, got " + list.size(), list.size() == 3);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:14,代码来源:ScriptAppenderSelectorTest.java


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