本文整理汇总了Java中org.apache.logging.log4j.test.appender.ListAppender类的典型用法代码示例。如果您正苦于以下问题:Java ListAppender类的具体用法?Java ListAppender怎么用?Java ListAppender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ListAppender类属于org.apache.logging.log4j.test.appender包,在下文中一共展示了ListAppender类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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
示例3: 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
示例4: testIsTraceEnabled
import org.apache.logging.log4j.test.appender.ListAppender; //导入依赖的package包/类
/**
* Tests isTraceEnabled.
*/
@Test
public void testIsTraceEnabled() {
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);
assertTrue(tracer.isTraceEnabled());
assertFalse(root.isTraceEnabled());
appender.stop();
root.getLogger().removeAppender(appender);
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:20,代码来源:LoggerTest.java
示例5: testLog
import org.apache.logging.log4j.test.appender.ListAppender; //导入依赖的package包/类
@Test
@SuppressWarnings("deprecation")
public void testLog() {
final PatternLayout layout = PatternLayout.createLayout("%d %C %L %m", null, null, null, null);
final ListAppender appender = new ListAppender("List", null, layout, false, false);
appender.start();
final Logger root = Logger.getRootLogger();
root.getLogger().addAppender(appender);
root.setLevel(Level.INFO);
final MyLogger log = new MyLogger(root);
log.logInfo("This is a test", null);
root.log(Priority.INFO, "Test msg2", null);
root.log(Priority.INFO, "Test msg3");
final List<String> msgs = appender.getMessages();
assertTrue("Incorrect number of messages", msgs.size() == 3);
final String msg = msgs.get(0);
assertTrue("Message contains incorrect class name: " + msg, msg.contains(LoggerTest.class.getName()));
appender.stop();
root.getLogger().removeAppender(appender);
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:21,代码来源:LoggerTest.java
示例6: verify
import org.apache.logging.log4j.test.appender.ListAppender; //导入依赖的package包/类
private void verify(final String expected) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Map<String, Appender> list = ctx.getConfiguration().getAppenders();
final Appender listApp = list.get("List");
assertNotNull("Missing Appender", listApp);
assertTrue("Not a ListAppender", listApp instanceof ListAppender);
final List<String> events = ((ListAppender) 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
{
((ListAppender) listApp).clear();
}
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:18,代码来源:CatchingTagTest.java
示例7: verify
import org.apache.logging.log4j.test.appender.ListAppender; //导入依赖的package包/类
private void verify(final String expected) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Map<String, Appender> list = ctx.getConfiguration().getAppenders();
final Appender listApp = list.get("List");
assertNotNull("Missing Appender", listApp);
assertTrue("Not a ListAppender", listApp instanceof ListAppender);
final List<String> events = ((ListAppender) listApp).getMessages();
try
{
assertEquals("Incorrect number of messages.", 1, events.size());
assertEquals("Incorrect message.", "o.a.l.l.t.EntryTagTest " + expected, events.get(0));
}
finally
{
((ListAppender) listApp).clear();
}
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:18,代码来源:EntryTagTest.java
示例8: verify
import org.apache.logging.log4j.test.appender.ListAppender; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void verify(final String expected) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Map<String, Appender> list = ctx.getConfiguration().getAppenders();
final Appender listApp = list.get("List");
assertNotNull("Missing Appender", listApp);
assertTrue("Not a ListAppender", listApp instanceof ListAppender);
final List<String> events = ((ListAppender) 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
{
((ListAppender) listApp).clear();
}
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:19,代码来源:LoggingMessageTagSupportTest.java
示例9: verify
import org.apache.logging.log4j.test.appender.ListAppender; //导入依赖的package包/类
private void verify(final String expected) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Map<String, Appender> list = ctx.getConfiguration().getAppenders();
final Appender listApp = list.get("List");
assertNotNull("Missing Appender", listApp);
assertTrue("Not a ListAppender", listApp instanceof ListAppender);
final List<String> events = ((ListAppender) listApp).getMessages();
try
{
assertEquals("Incorrect number of messages.", 1, events.size());
assertEquals("Incorrect message.", "o.a.l.l.t.ExitTagTest " + expected, events.get(0));
}
finally
{
((ListAppender) listApp).clear();
}
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:18,代码来源:ExitTagTest.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();
} else if (entry.getKey().equals("HostTest")) {
host = (ListAppender) entry.getValue();
} else if (entry.getKey().equals("NoThrowable")) {
noThrown = (ListAppender) entry.getValue();
}
}
assertNotNull("No Appender", app);
assertNotNull("No Host Appender", host);
app.clear();
host.clear();
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:18,代码来源:LoggerUpdateTest.java
示例11: setupClass
import org.apache.logging.log4j.test.appender.ListAppender; //导入依赖的package包/类
@BeforeClass
public static void setupClass() {
System.setProperty(Constants.LOG4J_LOG_EVENT_FACTORY, TestLogEventFactory.class.getName());
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
ctx = (LoggerContext) LogManager.getContext(false);
config = ctx.getConfiguration();
for (final Map.Entry<String, Appender> entry : config.getAppenders().entrySet()) {
if (entry.getKey().equals("List")) {
app = (ListAppender) entry.getValue();
break;
}
}
if (app == null) {
fail("No List Appender could be found");
}
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:17,代码来源:LogEventFactoryTest.java
示例12: testConfig
import org.apache.logging.log4j.test.appender.ListAppender; //导入依赖的package包/类
@Test
public void testConfig() {
final Configuration config = context.getConfiguration();
final Filter filter = config.getFilter();
assertNotNull("No MapFilter", filter);
assertTrue("Not a MapFilter", filter instanceof MapFilter);
final MapFilter mapFilter = (MapFilter) filter;
assertFalse("Should not be And filter", mapFilter.isAnd());
final Map<String, List<String>> map = mapFilter.getMap();
assertNotNull("No Map", map);
assertFalse("No elements in Map", map.isEmpty());
assertEquals("Incorrect number of elements in Map", 1, map.size());
assertTrue("Map does not contain key eventId", map.containsKey("eventId"));
assertEquals("List does not contain 2 elements", 2, map.get("eventId").size());
final Logger logger = LogManager.getLogger(MapFilterTest.class);
final Map<String, String> eventMap = new HashMap<>();
eventMap.put("eventId", "Login");
logger.debug(new StringMapMessage(eventMap));
final ListAppender app = context.getListAppender("LIST");
final List<String> msgs = app.getMessages();
assertNotNull("No messages", msgs);
assertFalse("No messages", msgs.isEmpty());
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:26,代码来源:MapFilterTest.java
示例13: 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
示例14: 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
示例15: testIsTraceEnabled
import org.apache.logging.log4j.test.appender.ListAppender; //导入依赖的package包/类
/**
* Tests isTraceEnabled.
*/
@Test
public void testIsTraceEnabled() {
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);
assertTrue(tracer.isTraceEnabled());
assertFalse(root.isTraceEnabled());
appender.stop();
} finally {
root.getLogger().removeAppender(appender);
}
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:23,代码来源:LoggerTest.java
示例16: testLog
import org.apache.logging.log4j.test.appender.ListAppender; //导入依赖的package包/类
@Test
@SuppressWarnings("deprecation")
public void testLog() {
final PatternLayout layout = PatternLayout.newBuilder().withPattern("%d %C %L %m").build();
final ListAppender appender = new ListAppender("List", null, layout, false, false);
appender.start();
final Logger root = Logger.getRootLogger();
try {
root.getLogger().addAppender(appender);
root.setLevel(Level.INFO);
final MyLogger log = new MyLogger(root);
log.logInfo("This is a test", null);
root.log(Priority.INFO, "Test msg2", null);
root.log(Priority.INFO, "Test msg3");
final List<String> msgs = appender.getMessages();
assertTrue("Incorrect number of messages", msgs.size() == 3);
final String msg = msgs.get(0);
assertTrue("Message contains incorrect class name: " + msg, msg.contains(LoggerTest.class.getName()));
appender.stop();
} finally {
root.getLogger().removeAppender(appender);
}
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:24,代码来源:LoggerTest.java
示例17: test
import org.apache.logging.log4j.test.appender.ListAppender; //导入依赖的package包/类
@Test
public void test() {
logger.info("This is a test.", new Exception("Test exception!"));
ListAppender listAppender = loggerContextRule.getListAppender("ListAppender");
Assert.assertNotNull(listAppender);
List<String> events = listAppender.getMessages();
Assert.assertNotNull(events);
Assert.assertEquals(1, events.size());
String logEvent = events.get(0);
Assert.assertNotNull(logEvent);
Assert.assertFalse("\"org.junit\" should not be here", logEvent.contains("org.junit"));
Assert.assertFalse("\"org.eclipse\" should not be here", logEvent.contains("org.eclipse"));
//
Layout<? extends Serializable> layout = listAppender.getLayout();
PatternLayout pLayout = (PatternLayout) layout;
Assert.assertNotNull(pLayout);
Serializer eventSerializer = pLayout.getEventSerializer();
Assert.assertNotNull(eventSerializer);
//
Assert.assertTrue("Missing \"|\"", logEvent.contains("|"));
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:22,代码来源:Log4j2_2195_Test.java
示例18: 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
示例19: 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
示例20: 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
注:本文中的org.apache.logging.log4j.test.appender.ListAppender类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论