首页 > 代码库 > 测试与log

测试与log

1 加载logback

private static void loadloack() {        LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();        JoranConfigurator configurator = new JoranConfigurator();        configurator.setContext(lc);        lc.reset();        try {            configurator.doConfigure("logback.xml");        } catch (JoranException e) {            e.printStackTrace();        }        StatusPrinter.printInCaseOfErrorsOrWarnings(lc);    }

 

2.加载log4j

 public static void loadlog4j(){        String file = AbstractDAOTests.class.getClassLoader()                   .getResource("./log4j.properties").getFile();  		PropertyConfigurator.configure(file);    }

 

3. ibatis配置sql打印

log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%nlog4j.logger.com.ibatis=debuglog4j.logger.com.ibatis.common.jdbc.SimpleDataSource=debuglog4j.logger.com.ibatis.common.jdbc.ScriptRunner=debuglog4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=debuglog4j.logger.java.sql.Connection=debuglog4j.logger.java.sql.Statement=debuglog4j.logger.java.sql.PreparedStatement=debug,stdout

 



测试与log