1 32 33 package org.slf4j; 34 35 import junit.framework.TestCase; 36 37 38 44 public class InvocationTest extends TestCase { 45 46 public InvocationTest (String arg0) { 47 super(arg0); 48 } 49 50 protected void setUp() throws Exception { 51 super.setUp(); 52 } 53 54 protected void tearDown() throws Exception { 55 super.tearDown(); 56 } 57 58 public void test1() { 59 Logger logger = LoggerFactory.getLogger("test1"); 60 logger.debug("Hello world."); 61 } 62 63 public void test2() { 64 Integer i1 = new Integer (1); 65 Integer i2 = new Integer (2); 66 Integer i3 = new Integer (3); 67 Exception e = new Exception ("This is a test exception."); 68 Logger logger = LoggerFactory.getLogger("test2"); 69 70 logger.debug("Hello world 1."); 71 logger.debug("Hello world {}", i1); 72 logger.debug("val={} val={}", i1, i2); 73 logger.debug("val={} val={} val={}", new Object []{i1, i2, i3}); 74 75 logger.debug("Hello world 2", e); 76 logger.info("Hello world 2."); 77 78 79 logger.warn("Hello world 3."); 80 logger.warn("Hello world 3", e); 81 82 83 logger.error("Hello world 4."); 84 logger.error("Hello world {}", new Integer (3)); 85 logger.error("Hello world 4.", e); 86 } 87 88 public void testNull() { 89 Logger logger = LoggerFactory.getLogger("testNull"); 90 logger.debug(null); 91 logger.info(null); 92 logger.warn(null); 93 logger.error(null); 94 95 Exception e = new Exception ("This is a test exception."); 96 logger.debug(null, e); 97 logger.info(null, e); 98 logger.warn(null, e); 99 logger.error(null, e); 100 } 101 102 public void testMarker() { 103 Logger logger = LoggerFactory.getLogger("testMarker"); 104 Marker blue = MarkerFactory.getMarker("BLUE"); 105 logger.debug(blue, "hello"); 106 logger.info(blue, "hello"); 107 logger.warn(blue, "hello"); 108 logger.error(blue, "hello"); 109 110 logger.debug(blue, "hello {}", "world"); 111 logger.info(blue, "hello {}", "world"); 112 logger.warn(blue, "hello {}", "world"); 113 logger.error(blue, "hello {}", "world"); 114 115 logger.debug(blue, "hello {} and {} ", "world", "universe"); 116 logger.info(blue, "hello {} and {} ", "world", "universe"); 117 logger.warn(blue, "hello {} and {} ", "world", "universe"); 118 logger.error(blue, "hello {} and {} ", "world", "universe"); 119 } 120 121 public void testMDC() { 122 MDC.put("k", "v"); 123 assertNull(MDC.get("k")); 124 MDC.remove("k"); 125 assertNull(MDC.get("k")); 126 MDC.clear(); 127 } 128 } 129 | Popular Tags |