版本一:把日志和错误日志进行存档到指定硬盘,并查看所有的日志信息。
在log4j.properties中配置如下即可:(可以根据自己所需要的设置)
### set log levels ###
log4j.rootLogger = DEBUG,stdout,D,E
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.Threshold = INFO
#INFO
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss} %l%m%n
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File =
F://logs/log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File =
F://logs/error.log
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
log4j.appender.Console.layout=com.lnsf.warehouse.util.ColoredPatternLayout
log4j.appender.Console.layout.ErrorColor=red
log4j.appender.Console.layout.DebugColor=black
#/green/blue/bright
版本二:使用mybatis,即可查看数据库后台的日志。(ssm,ssh都可以用,亲测有效)
log4j打印mybatis完整sql,在log4j.properties中配置如下即可:
log4j.rootLogger=DEBUG,stdout
log4j.logger.com.ibatis=DEBUG
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-5p %d{yyyy-MM-dd HH:mm:ssS} %m%n
效果截图:
备注:所需jar包如下:
mybatis.jar、 slf4j-api.jar、slf4j-log4j12.jar