springMVC+Spring+Mybatis控制台输出sql,配置log4j.properties文件

前提:SSM框架搭建完毕,jar包全都已导入
一:在web.xml文件中配置监听器,配置代码如下:
   
   
          org.springframework.web.util.Log4jConfigListener
   

   
         contextConfigLocation
         classpath:log4j.properties
   

二:监听器配置完毕之后,在配置文件夹中新建配置文件log4j.properties文件,将如下代码贴入log4j.properties配置文件中:


# Configures Log4j for Tomcat and Sakai


# use "A" for log in with catalina.out (actually standard output)
log4j.rootLogger=WARN, Sakai


# Configuration for standard output ("catalina.out" in Tomcat).
log4j.appender.Sakai=org.apache.log4j.ConsoleAppender
log4j.appender.Sakai.layout=org.apache.log4j.PatternLayout
#log4j.appender.Sakai.layout.ConversionPattern=%p: %m (%d %t_%c)%n


# A more descriptive but lower performance logging pattern
log4j.appender.Sakai.layout.ConversionPattern=%d{ISO8601} %5p %t %c - %m%n


# Configuration for a rolling log file ("tomcat.log")
#log4j.appender.Sakai=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.Sakai.DatePattern='.'yyyy-MM-dd
#log4j.appender.Sakai.File=/usr/local/tomcat/logs/tomcat.log
#log4j.appender.Sakai.layout=org.apache.log4j.PatternLayout
#log4j.appender.Sakai.layout.ConversionPattern=%p %d %t_%c%n%m%n


#Set the encoding on the appender KNL-448
log4j.appender.Sakai.Encoding=UTF-8


# Application logging options
log4j.logger.org.apache=INFO
log4j.logger.org.sakaiproject=INFO
log4j.logger.uk.ac.cam.caret.rwiki=INFO
log4j.logger.org.theospi=INFO
log4j.logger.MySQL=INFO
log4j.logger.org.springframework=DEBUG
log4j.logger.cn.edu.hbcf=DEBUG
log4j.logger.com.yunzai=DEBUG


# Ignore erroneous MyFaces warnings
log4j.logger.org.apache.myfaces.el.VariableResolverImpl=ERROR
log4j.logger.org.apache.myfaces.shared_impl.webapp.webxml.WebXmlParser=ERROR
log4j.logger.org.apache.myfaces.shared_tomahawk.webapp.webxml.WebXmlParser=ERROR




# Setup vm levels
log4j.logger.vm.none=FATAL
log4j.logger.vm.error=ERROR
log4j.logger.vm.warn=WARN
log4j.logger.vm.info=INFO
log4j.logger.vm.debug=DEBUG




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  
log4j.logger.java.sql.ResultSet=DEBUG
log4j.logger.org.apache.ibatis.io=DEBUG




至此完毕,可进行运行,查看控制台是否报错,




注:完毕之后我的控制台有报错,是少了Junit包,于是在网上下载了一个Junit-4.4的jar包,导入之后正常开启,成功

你可能感兴趣的:(java)