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.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n log4j.logger.com.ibatis=debug log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=debug log4j.logger.com.ibatis.common.jdbc.ScriptRunner=debug log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=debug log4j.logger.java.sql.Connection=debug log4j.logger.java.sql.Statement=debug log4j.logger.java.sql.PreparedStatement=debug,stdout
原文:http://www.cnblogs.com/hero4china/p/5829059.html