1 package org.exoplatform.services.log.impl; 2 3 4 import org.apache.commons.logging.Log; 5 import org.exoplatform.container.PortalContainer; 6 import org.exoplatform.services.log.LogService; 7 import org.exoplatform.services.log.LogUtil; 8 import org.exoplatform.test.BasicTestCase; 9 10 14 15 22 public class TestLogService extends BasicTestCase { 23 24 LogService service_ ; 25 26 public TestLogService(String name) { 27 super(name); 28 } 29 30 protected String getDescription() { 31 return "Log service test"; 32 } 33 34 public void setUp() throws Exception { 35 setTestNumber(1) ; 36 System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); 37 PortalContainer manager = PortalContainer.getInstance(); 38 service_ = (LogService) manager.getComponentInstanceOfType(LogService.class) ; 39 } 40 41 public void tearDown() throws Exception { 42 } 43 44 public void testLogService() throws Exception { 45 Log log = service_.getLog("org.exoplatform.services.log"); 46 Log sublog = service_.getLog("org.exoplatform.services.log.sublog"); 47 assertEquals(LogService.INFO, service_.getLogLevel("org.exoplatform.services.log")); 48 assertEquals(LogService.INFO, service_.getLogLevel("org.exoplatform.services.log.sublog")); 49 log.debug("debug: test category 'org.exoplatform.services.log'"); 50 log.info("info: test category 'org.exoplatform.services.log'"); 51 log.warn("warn: test category 'org.exoplatform.services.log'"); 52 log.error("error: test category 'org.exoplatform.services.log'"); 53 service_.setLogLevel("org.exoplatform.services.log", LogService.ERROR, true) ; 54 assertEquals(LogService.ERROR, service_.getLogLevel("org.exoplatform.services.log")); 55 assertEquals(LogService.ERROR, service_.getLogLevel("org.exoplatform.services.log.sublog")); 56 57 LogUtil.debug("This is a test debug") ; 58 LogUtil.info("This is a test inof") ; 59 LogUtil.warn("This is a test warn") ; 60 LogUtil.error("This is a test error") ; 61 62 } 63 } | Popular Tags |