jar包不能少:F:jarsslf4j-api-1.7.5.jar F:strutsWsoldslf4j-1.7.5slf4j-1.7.5slf4j-log4j12-1.7.5.jar F:log4j-1.2.17log4j-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