今日初上手springboot,
想查mybatis的sql报错信息,所有想打印dao层debug日志。
于是配置了log4j.xml,但是没有生效,后发现时是springboot默认使用logback日志。
1.移除logback改用log4j,需要修改pom.xml文件:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- log4j -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>1.3.8.RELEASE</version>
</dependency>
2.在log4j中,指定dao层日志输出级别:
#mybatis, debug level to see sql
log4j.logger.com.xx.cd.dao=debug
启动后看到输出的sql日志信息。
3.log4j.xml内容:
4. # Output pattern : date [thread] priority category - message
log4j.rootCategory=debug, Console, R
#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
#/opt/apps/epp-manager/var/logs/epp-manager.log
log4j.appender.R.File=/var/logs/Secret-CD/Secret-CD.log
log4j.appender.R.DatePattern='.'yyyy-MM-dd
log4j.appender.R.MaxFileSize=20MB
log4j.appender.R.MaxBackupIndex=30
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n