-
自定义规则conversionRule
public class LogabckMessageConverter extends MessageConverter {@Overridepublic String convert(ILoggingEvent event) {String msg = event.getMessage();if ("INFO".equals(event.getLevel().toString())) {msg = .....脱敏实现}return msg;} }
-
logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?> <configuration scan="true" scanPeriod="10 seconds"><springProperty scope="context" name="logging.path"source="log_path_base" /><property name="LOG_FILE_PREFIX" value="60760" /><!--自定义脱敏规则--><conversionRule conversionWord="msg" converterClass="com.xxx.LogabckMessageConverter"/><appender name="FILE" class="ch.qos.logback.core.FileAppender"> <file>/logs/testFile.log</file> <append>true</append> <encoder> <!--日志打印模板--><pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern> </encoder> </appender> <!-- 控制台日志 --><appender name="STDOUT"class="ch.qos.logback.core.ConsoleAppender"><encoder><pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern><charset>UTF-8</charset></encoder></appender><root level="INFO"><appender-ref ref="STDOUT" /> <appender-ref ref="FILE" /> </root> </configuration>