代码
<appendername="STDOUT"class="ch.qos.logback.core.ConsoleAppender"><layoutclass="ch.qos.logback.classic.PatternLayout"><pattern>%-15(%d{HH:mm:ss.SSS}) [%t] %-5level%logger{80} [%line] -%msg%n</pattern></layout></appender><appendername="SIFT"class="ch.qos.logback.classic.sift.SiftingAppender"><discriminator><key>module</key><defaultValue>module</defaultValue></discriminator><sift><appendername="FILE-${module}"class="ch.qos.logback.core.rolling.RollingFileAppender"><Encoding>UTF-8</Encoding><rollingPolicyclass="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><FileNamePattern>${log.root}/${module}/${module}.%d{yyyy-MM-dd}.log</FileNamePattern></rollingPolicy><layoutclass="ch.qos.logback.classic.PatternLayout"><pattern>%-15(%d{HH:mm:ss.SSS}) [%t] %-5level%logger{80} [%line] -%msg%n</pattern></layout></appender></sift></appender><rootlevel="info"><appender-refref="STDOUT"/><appender-refref="SIFT"/></root><loggername="com.shangyu"level="debug"additivity="true"><appender-refref="STDOUT"/><!--<appender-refref="SIFT"/>--></logger>
STDOUT 是打印在控制台,控制台的日志如下
19:33:04.696 [http-nio-8080-exec-2] DEBUGcom.shangyu.demo.mapper.UserMapper.selectById [143] -==>Preparing: SELECTid,name,age,address,father_nameFROMalin_userWHEREid=?19:33:04.696 [http-nio-8080-exec-2] DEBUGcom.shangyu.demo.mapper.UserMapper.selectById [143] -==>Preparing: SELECTid,name,age,address,father_nameFROMalin_userWHEREid=?19:33:04.729 [http-nio-8080-exec-2] DEBUGcom.shangyu.demo.mapper.UserMapper.selectById [143] -==>Parameters: 1(Integer) 19:33:04.729 [http-nio-8080-exec-2] DEBUGcom.shangyu.demo.mapper.UserMapper.selectById [143] -==>Parameters: 1(Integer) 19:33:04.759 [http-nio-8080-exec-2] DEBUGcom.shangyu.demo.mapper.UserMapper.selectById [143] -<==Total: 119:33:04.759 [http-nio-8080-exec-2] DEBUGcom.shangyu.demo.mapper.UserMapper.selectById [143] -<==Total: 119:33:04.768 [http-nio-8080-exec-2] INFOcom.shangyu.demo.controller.UserController [35] -info19:33:04.768 [http-nio-8080-exec-2] INFOcom.shangyu.demo.controller.UserController [35] -info19:33:04.769 [http-nio-8080-exec-2] ERRORcom.shangyu.demo.controller.UserController [36] -error19:33:04.769 [http-nio-8080-exec-2] ERRORcom.shangyu.demo.controller.UserController [36] -error19:33:04.769 [http-nio-8080-exec-2] DEBUGcom.shangyu.demo.controller.UserController [37] -debug19:33:04.769 [http-nio-8080-exec-2] DEBUGcom.shangyu.demo.controller.UserController [37] -debug
SIFT 是打印日志到文件,粘一些文件中的日志如下
19:33:04.696 [http-nio-8080-exec-2] DEBUGcom.shangyu.demo.mapper.UserMapper.selectById [143] -==>Preparing: SELECTid,name,age,address,father_nameFROMalin_userWHEREid=?19:33:04.729 [http-nio-8080-exec-2] DEBUGcom.shangyu.demo.mapper.UserMapper.selectById [143] -==>Parameters: 1(Integer) 19:33:04.759 [http-nio-8080-exec-2] DEBUGcom.shangyu.demo.mapper.UserMapper.selectById [143] -<==Total: 119:33:04.768 [http-nio-8080-exec-2] INFOcom.shangyu.demo.controller.UserController [35] -info19:33:04.769 [http-nio-8080-exec-2] ERRORcom.shangyu.demo.controller.UserController [36] -error19:33:04.769 [http-nio-8080-exec-2] DEBUGcom.shangyu.demo.controller.UserController [37] -debug
总结
- 当additivity设为true时,这个logger标签会继承root,也就不仅仅打印自己的日志,还会打印root的日志,打印两遍。所以一般情况下都会设置成false