个人博客
SpringBoot默认采用logback作为日志输出。
1、参数含义
参数 | 含义 |
---|
%date或%d | 日期 |
%level或%p | 日志级别,DEBUG、INFO、WARN、ERROR |
%X{var} | 访问MDC中和线程绑定的变量 |
%thread或%t | 线程名 |
%logger或%c | 类全名 |
%line | 行号 |
%msg或%m | 输出内容 |
%n | 换行符 |
2、xml参考配置
日志配置文件一般命名为logback-spring.xml
或logback.xml
,日志框架在启动时默认就会读取该配置。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| <?xml version="1.0" encoding="UTF-8"?> <configuration> <springProperty scope="context" name="appName" source="spring.application.name"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>info</level> </filter>
<encoder> <charset>UTF-8</charset> <Pattern>%d [%p] [%t] [%c:%line] [%X{seq}] %m%n</Pattern> </encoder> </appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${user.home}/log/${appName}.log</file> <encoder> <charset>UTF-8</charset> <pattern>%d [%p] [%t] [%c:%line] [%X{seq}] %m%n</pattern> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${user.home}/log/${appName}.log.%d{yyyyMMdd}.gz</fileNamePattern> <maxHistory>30</maxHistory> </rollingPolicy>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>info</level> </filter> </appender>
<appender name="WarnController" class="ch.qos.logback.core.ConsoleAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>warn</level> </filter> <encoder> <charset>UTF-8</charset> <Pattern>%d [%p] [%t] [%c:%line] [%X{seq}] %m%n</Pattern> </encoder> </appender> <logger name="net.zhaoxiaobin.web.WarnController" level="warn" additivity="false"> <appender-ref ref="WarnController"/> </logger>
<root level="debug"> <appender-ref ref="CONSOLE"/> <appender-ref ref="FILE"/> </root>
</configuration>
|
代码地址