1 <?xml version="1.0" encoding="UTF-8"?>
2 <configuration>
3 <!-- 控制台日志打印,测试环境和调试使用,发布生产需注释 -->
4 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
5 <encoder charset="utf-8"> <!-- encoder 可以指定字符集,对于中文输出有意义 -->
6 <!-- %.-1level 只显示信息级别的首字母,%-5level 左对齐显示信息级别全称 -->
7 <!-- 如需自定义关键字,用 %mdc{键名} 表示,程序中用MDC.put("键名","键值")设置,可动态设置 [%logger:%line]-->
8 <Pattern>[%date{yyyy-MM-dd HH:mm:ss}] [%-5level] %c{40} %line --%mdc{client} [%X{TRACE_LOG_ID}] %msg%n</Pattern>
9 </encoder>>
10 </appender>
11
12 <!-- 系统日志打印 -->
13 <appender name="logfile" class="ch.qos.logback.core.rolling.RollingFileAppender">
14 <File>/log/ma/ma-test.log</File>
15 <encoder>
16 <Pattern>[%date] [%-5level] %c{40} %line --%mdc{client} [%X{TRACE_LOG_ID}] %msg%n</Pattern>
17 <charset>UTF-8</charset>
18 </encoder>
19 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
20 <fileNamePattern>/log//ma/ma-test.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
21 <maxHistory>30</maxHistory>
22 <TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
23 <maxFileSize>512MB</maxFileSize>
24 </TimeBasedFileNamingAndTriggeringPolicy>
25 </rollingPolicy>
26 </appender>
27 <logger level="ERROR" name="com.mchange" />
28 <logger level="ERROR" name="com.ibatis" />
29 <logger level="ERROR" name="org.mybatis" />
30 <logger level="INFO" name="org.springframework"/>
31 <logger level="ERROR" name="java.sql"/>
32 <logger level="ERROR" name="org.apache"/>
33 <logger level="INFO" name="com.alibaba"/>
34 <logger level="INFO" name="org.apache.zookeeper"/>
35 <logger level="ERROR" name="org.I0Itec"/>
36 <logger level="ERROR" name="org.dozer"/>
37 <logger level="OFF" name="org.jdbcdslog"/>
38 <logger level="ERROR" name="java.sql.SQLException"/>
39 <logger level="ERROR" name="org.jdbcdslog.StatementLogger"/>
40 <logger level="OFF" name="org.springframework.dao.CannotAcquireLockException"/>
41
42 <!-- 输出到文件,可定义更多的 Appender -->
43 <root level="INFO" name="com.ht.clear.test">
44 <appender-ref ref="logfile" />
45 </root>
46
47 <!-- 输出到控制台和文件,可定义更多的 Appender -->
48 <root level="DEBUG">
49 <appender-ref ref="STDOUT"/>
50 </root>
51
52 </configuration>
详细搭建过程参考:https://www.cnblogs.com/xiuxingzhe/p/9250737.html