MyBatis集成log4j

1.在pom.xml导入三个jar包


<dependency>
  <groupId>org.slf4jgroupId>
  <artifactId>slf4j-apiartifactId>
  <version>1.7.4version>
dependency>


<dependency>
  <groupId>org.slf4jgroupId>
  <artifactId>slf4j-log4j12artifactId>
  <version>1.7.5version>
  <scope>testscope>
dependency>
<dependency>
  <groupId>log4jgroupId>
  <artifactId>log4jartifactId>
  <version>1.2.17version>
dependency>

2.在resous文件下创建log4j.properties

### 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 mylog.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=c\://log//mylog.log  //记录日志的文件位置
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.logger.cn.happy.dao=trace,stdout

log4j.logger.cn.happy.dao=trace,stdout

cn.happy.dao与你所创建的包对应


控制台log4j显示的结果:

MyBatis集成log4j_第1张图片

你可能感兴趣的:(MyBatis集成log4j)