本文整理汇总了Java中org.apache.logging.log4j.test.appender.ListAppender.stop方法的典型用法代码示例。如果您正苦于以下问题:Java ListAppender.stop方法的具体用法?Java ListAppender.stop怎么用?Java ListAppender.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.logging.log4j.test.appender.ListAppender
的用法示例。
在下文中一共展示了ListAppender.stop方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例3: 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);
}
示例4: 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);
}
示例5: 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));
}
示例6: 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);
}
}
示例7: 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);
}
}
示例8: testLayout
import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
/**
* Test case for MDC conversion pattern.
*/
@Test
public void testLayout() throws Exception {
// set up appender
final XMLLayout layout = XMLLayout.createLayout("true", "true", "true", null, null, null);
final ListAppender appender = new ListAppender("List", null, layout, true, false);
appender.start();
// set appender on root and set level to debug
root.addAppender(appender);
root.setLevel(Level.DEBUG);
// output starting message
root.debug("starting mdc pattern test");
root.debug("empty mdc");
ThreadContext.put("key1", "value1");
ThreadContext.put("key2", "value2");
root.debug("filled mdc");
ThreadContext.remove("key1");
ThreadContext.remove("key2");
root.error("finished mdc pattern test", new NullPointerException("test"));
appender.stop();
final List<String> list = appender.getMessages();
assertTrue("Incorrect number of lines. Require at least 50 " + list.size(), list.size() > 50);
final String string = list.get(0);
assertTrue("Incorrect header: " + string, string.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
assertTrue("Incorrect footer", list.get(list.size() - 1).equals("</Events>"));
assertTrue("Incorrect body. Expected " + body + " Actual: " + list.get(7), list.get(7).trim().equals(body));
}
示例9: testLayoutNormalApi
import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
static void testLayoutNormalApi(final Logger root, final AbstractCsvLayout layout, final boolean messageApi)
throws Exception {
removeAppenders(root);
// set up appender
final ListAppender appender = new ListAppender("List", null, layout, true, false);
appender.start();
appender.countDownLatch = new CountDownLatch(4);
// set appender on root and set level to debug
root.addAppender(appender);
root.setLevel(Level.DEBUG);
// output messages
if (messageApi) {
logDebugObjectArrayMessage(root);
} else {
logDebugNormalApi(root);
}
final int msgCount = 4;
if (appender.getMessages().size() < msgCount) {
// wait until background thread finished processing
appender.countDownLatch.await(10, 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 char d = layout.getFormat().getDelimiter();
Assert.assertEquals("1" + d + "2" + d + "3", list.get(0));
Assert.assertEquals("2" + d + "3", list.get(1));
Assert.assertEquals("5" + d + "6", list.get(2));
Assert.assertEquals("7" + d + "8" + d + "9" + d + "10", list.get(3));
}
示例10: 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);
}
}
示例11: testHeader
import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
@Test
public void testHeader() {
final ListAppender listApp = context.getListAppender("List");
final Logger logger = context.getLogger(this.getClass().getName());
logger.info("Hello World");
final List<String> messages = listApp.getMessages();
Assert.assertFalse(messages.isEmpty());
final String messagesStr = messages.toString();
Assert.assertEquals(messagesStr, "Header: value0", messages.get(0));
listApp.stop();
Assert.assertEquals(messagesStr, "Footer: value1", messages.get(2));
}
示例12: testLayout
import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
/**
* Test case for MDC conversion pattern.
*/
@Test
public void testLayout() throws Exception {
// set up appender
final JSONLayout layout = JSONLayout.createLayout("true", "true", "true", "false", null);
final ListAppender appender = new ListAppender("List", null, layout, true, false);
appender.start();
// set appender on root and set level to debug
this.root.addAppender(appender);
this.root.setLevel(Level.DEBUG);
// output starting message
this.root.debug("starting mdc pattern test");
this.root.debug("empty mdc");
ThreadContext.put("key1", "value1");
ThreadContext.put("key2", "value2");
this.root.debug("filled mdc");
ThreadContext.remove("key1");
ThreadContext.remove("key2");
this.root.error("finished mdc pattern test", new NullPointerException("test"));
appender.stop();
final List<String> list = appender.getMessages();
// System.out.println(list);
// [[, {, "logger":"root",, "timestamp":"1376676700199",, "level":"DEBUG",, "thread":"main",,
// "message":"starting mdc pattern test",, "LocationInfo":{,
// "class":"org.apache.logging.log4j.core.layout.JSONLayoutTest",, "method":"testLayout",,
// "file":"JSONLayoutTest.java",, "line":"87", }, },, {, "logger":"root",, "timestamp":"1376676700203",,
// "level":"DEBUG",, "thread":"main",, "message":"empty mdc",, "LocationInfo":{,
// "class":"org.apache.logging.log4j.core.layout.JSONLayoutTest",, "method":"testLayout",,
// "file":"JSONLayoutTest.java",, "line":"89", }, },, {, "logger":"root",, "timestamp":"1376676700204",,
// "level":"DEBUG",, "thread":"main",, "message":"filled mdc",, "LocationInfo":{,
// "class":"org.apache.logging.log4j.core.layout.JSONLayoutTest",, "method":"testLayout",,
// "file":"JSONLayoutTest.java",, "line":"94", },, "Properties":[, {, "name":"key2",, "value":"value2", },, {,
// "name":"key1",, "value":"value1", }, ], },, {, "logger":"root",, "timestamp":"1376676700204",,
// "level":"ERROR",, "thread":"main",, "message":"finished mdc pattern test",,
// "throwable":"java.lang.NullPointerException: test\\n\\tat org.apache.logging.log4j.core.layout.JSONLayoutTest.testLayout(JSONLayoutTest.java:99)\\n\\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\\n\\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\\n\\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\n\\tat java.lang.reflect.Method.invoke(Method.java:606)\\n\\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)\\n\\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\\n\\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)\\n\\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\\n\\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)\\n\\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)\\n\\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)\\n\\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)\\n\\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)\\n\\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)\\n\\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)\\n\\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)\\n\\tat org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)\\n\\tat org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)\\n\\tat org.junit.runners.ParentRunner.run(ParentRunner.java:309)\\n\\tat org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)\\n\\tat org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)\\n\\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)\\n\\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)\\n\\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)\\n\\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)\\n",,
// "LocationInfo":{, "class":"org.apache.logging.log4j.core.layout.JSONLayoutTest",, "method":"testLayout",,
// "file":"JSONLayoutTest.java",, "line":"99", }, },, ]]
this.checkAt("[", 0, list);
this.checkAt("{", 1, list);
this.checkAt("\"logger\":\"root\",", 2, list);
this.checkAt("\"level\":\"DEBUG\",", 4, list);
this.checkAt("\"message\":\"starting mdc pattern test\",", 6, list);
}
示例13: testLayout
import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
/**
* Test case for MDC conversion pattern.
*/
@Test
public void testLayout() {
// set up appender
final HTMLLayout layout = HTMLLayout.createLayout("true", null, null, null, "small", null);
final ListAppender appender = new ListAppender("List", null, layout, true, false);
appender.start();
// set appender on root and set level to debug
root.addAppender(appender);
root.setLevel(Level.DEBUG);
// output starting message
root.debug("starting mdc pattern test");
root.debug("empty mdc");
root.debug("First line\nSecond line");
ThreadContext.put("key1", "value1");
ThreadContext.put("key2", "value2");
root.debug("filled mdc");
ThreadContext.remove("key1");
ThreadContext.remove("key2");
root.error("finished mdc pattern test", new NullPointerException("test"));
appender.stop();
final List<String> list = appender.getMessages();
assertTrue("Incorrect number of lines. Require at least 85 " + list.size(), list.size() > 85);
final String string = list.get(3);
assertTrue("Incorrect header: " + string, string.equals("<meta charset=\"UTF-8\"/>"));
assertTrue("Incorrect title", list.get(4).equals("<title>Log4j Log Messages</title>"));
assertTrue("Incorrect footer", list.get(list.size() - 1).equals("</body></html>"));
assertTrue("Incorrect multiline", list.get(50).equals(multiLine));
assertTrue("Incorrect body", list.get(71).equals(body));
}
示例14: testLayout
import org.apache.logging.log4j.test.appender.ListAppender; //导入方法依赖的package包/类
/**
* Test case for MDC conversion pattern.
*/
@Test
public void testLayout() throws Exception {
// set up appender
final SerializedLayout layout = SerializedLayout.createLayout();
final ListAppender appender = new ListAppender("List", null, layout, false, true);
appender.start();
// set appender on root and set level to debug
root.addAppender(appender);
root.setLevel(Level.DEBUG);
// output starting message
root.debug("starting mdc pattern test");
root.debug("empty mdc");
ThreadContext.put("key1", "value1");
ThreadContext.put("key2", "value2");
root.debug("filled mdc");
ThreadContext.remove("key1");
ThreadContext.remove("key2");
root.error("finished mdc pattern test", new NullPointerException("test"));
final Exception parent = new IllegalStateException("Test");
final Throwable child = new LoggingException("This is a test", parent);
root.error("Throwing an exception", child);
appender.stop();
final List<byte[]> data = appender.getData();
assertTrue(data.size() > 0);
int i = 0;
for (final byte[] item : data) {
final ByteArrayInputStream bais = new ByteArrayInputStream(item);
final ObjectInputStream ois = new ObjectInputStream(bais);
LogEvent event;
try {
event = (LogEvent) ois.readObject();
} catch (final IOException ioe) {
System.err.println("Exception processing item " + i);
throw ioe;
}
assertTrue("Incorrect event", event.toString().equals(expected[i]));
++i;
}
}