jar包不能少:F:\jars\slf4j-api-1.7.5.jar F:\strutsWsold\slf4j-1.7.5\slf4j-1.7.5\slf4j-log4j12-1.7.5.jar F:\log4j-1.2.17\log4j-1.2.17.jar
第一個是slf介面jar,第二個是slf和log4j介面中轉jar,第三個是log4j實現jar。
需要在src下新增 log4j.properties檔案,內容如下
給檔案可以在控制檯輸出log,還能生成硬碟log檔案。
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.File=hibernate.log
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.hfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.hfile.File=C:/test/log_bias.log
#${webApp.root}/WEB-INF/logs/info.log
log4j.appender.hfile.layout=org.apache.log4j.PatternLayout
log4j.appender.hfile.layout.ConversionPattern= %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=warn,stdout,info,hfile
#log4j.logger.org.hibernate=info
log4j.logger.org.hibernate=debug
### log HQL query parser activity
#log4j.logger.org.hibernate.hql.ast.AST=debug
### log just the SQL
#log4j.logger.org.hibernate.SQL=debug
### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=info
#log4j.logger.org.hibernate.type=debug
### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug
### log HQL parse trees
#log4j.logger.org.hibernate.hql=debug
### log cache activity ###
#log4j.logger.org.hibernate.cache=debug
### log transaction activity
#log4j.logger.org.hibernate.transaction=debug
### log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=debug
### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace