SpringBoot默认使用logback做为日志框架 ,因此引入起步依赖后就能够直接使用logback,不须要其余依赖。java
SpringBoot会默认加载classpath:logback.xml或者classpath:logback-spring.xml 做为日志的配置文件,在springboot项目中能够直接把日志配置文件放在resources目录下。spring
简单使用时也能够不使用日志配置文件,将日志相关的配置直接放在application.yml中,以下sql
#日志设置 logging: file: root.log level: com: lyy: dao: debug
其中file选项用来指定日志文件输出的位置,能够是相对路径,也能够是绝对路径。springboot
level选项用来指定日志的级别,能够指定总的级别level: info
,也能够像上边这样指定某个包中日志的输出级别。mybatis
logback中支持使用slf4j来记录日志,因此能够使用以下的方式来记录日志app
private final static Logger logger= LoggerFactory.getLogger(CategoryDataServiceImpl.class);
这里须要导入如下两个类,都是slf4j中的类框架
import org.slf4j.Logger; import org.slf4j.LoggerFactory;
使用日志记录器来记录日志学习
logger.info("com.lyy.service.impl.CategoryDataServiceImpl.findAll is run");
springboot整合mbatis后如何把sql语句输出到日志文件中,spa
由于mybatis输出sql的日志级别默认是debug,因此这里有两种实现方式:debug
(1) 把整个工程的日志级别都调整成debug,按一中的方法level: info
,
(2) 指定dao接口所在的包的日志输出级别是debug
#日志设置 logging: file: root.log level: com: lyy: dao: debug
按上面的方法配置后就能够把mybatis的sql输出到日志文件中