当前位置:网站首页>Simple third-party component log desensitization
Simple third-party component log desensitization
2022-07-19 09:04:00 【Fire king】
Simple third-party component log desensitization
- 1. download jar Pack and enter your local warehouse
- 2. rely on
- 3. Log depends on
- 4. Desensitization rules -logback-desensitize.yml
- 5.logback.xml
- 6.application.yml
- 7.logback.xml Replace with desensitized class
- 8. test
- 9.demo structure
- 10.gitee Address
- 11.[ Reference resources ](https://blog.csdn.net/m0_48333563/article/details/125806919?csdn_share_tail=%7B%22type%22:%22blog%22,%22rType%22:%22article%22,%22rId%22:%22125806919%22,%22source%22:%22m0_48333563%22%7D&ctrtid=sz8a4)
- 12. Resource upload
1. download jar Pack and enter your local warehouse

Find anywhere ,mvn -v Make sure maven Warehouse configuration is correct
stay jar The folder is open cmd terminal , type
mvn install:install-file -DgroupId=pers.liuchengyin -DartifactId=logback-desensitization -Dversion=1.0.0 -Dpackaging=jar -Dfile=logback-desensitization-1.0.0.jar
2. rely on
<dependency>
<groupId>pers.liuchengyin</groupId>
<artifactId>logback-desensitization</artifactId>
<version>1.0.0</version>
</dependency>
3. Log depends on
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
4. Desensitization rules -logback-desensitize.yml
# Log desensitization
log-desensitize:
# Whether to ignore case matching , The default is true
ignore: true
# Whether desensitization is enabled , The default is false
open: true
# pattern Under the key/value For fixed desensitization rules
pattern:
# mailbox - @ The first 4-7 Bit desensitization
email: "@>(4,7)"
# qq mailbox - @ after 1-3 Bit desensitization
qqemail: "@<(1,3)"
# full name - Surname desensitization , Such as * jay
name: 1,1
# password - All that need complete desensitization can use the built-in password
password: password
patterns:
# ID number ,key The following fields can match the following rules ( Separate with commas )
- key: identity,idcard
# Define the identification of the rule
custom:
# defaultRegex It means to use the built-in rules of the component :identity Indicating ID number - Built in 18/15 position
- defaultRegex: identity
position: 9,13
# Built in other It means that if other rules cannot match , Then follow this rule
- defaultRegex: other
position: 9,10
# Phone number ,key The following fields can match the following rules ( Separate with commas )
- key: phone,cellphone,mobile
custom:
# cell-phone number - Built in 11 Bit mobile phone matching rules
- defaultRegex: phone
position: 4,7
# Custom regular matching expression : Seat number ( With area code , The number is seven digits | Octet )
- customRegex: "^0[0-9]{2,3}-[0-9]{7,8}"
# - hinder 1-4 Bit desensitization
position: "-<(1,4)"
# Custom regular matching expression : Seat number ( No area code )
- customRegex: "^[0-9]{7,8}"
position: 3,5
# Built in other It means that if other rules cannot match , Then follow this rule
- defaultRegex: other
position: 1,3
# This way is not recommended - Once it doesn't match , Will not desensitize
- key: localMobile
custom:
customRegex: "^0[0-9]{2,3}-[0-9]{7,8}"
position: 1,3
5.logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!--spring boot Provided logback Default configuration , Must quote , Otherwise, the log cannot be output -->
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<!-- Configure centrally managed properties -->
<property resource="application.yml"/>
<!-- Color log depends on rendering class -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
<conversionRule conversionWord="wex"
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
<conversionRule conversionWord="wEx"
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
<!-- Define the storage address of the log file -->
<property name="LOG_HOME" value="logs"/>
<property name="FILE_NAME" value="${LOG_HOME}/%d{yyyy-MM-dd}"/>
<!-- Define your own log format -->
<property name="PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %c{50} %M %L -- %m%n"/>
<!--
%d{
yyyy-MM-dd HH:mm:ss.SSS} Date format
%c Full name of the class
%logger Full name of the class
%M Method name
%L Line number
%thread Threads
%m Information
%n Line break
%-5level Information level
-->
<!-- Console output -->
<appender name="STDOUT" class="pers.liuchengyin.logbackadvice.LcyConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${PATTERN}</pattern>
</encoder>
</appender>
<!-- Generate log files per day -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- The filename of the log file output -->
<FileNamePattern>${FILE_NAME}_all.txt</FileNamePattern>
<!-- Log file retention days -->
<MaxHistory>7</MaxHistory>
<totalSizeCap>512MB</totalSizeCap>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${PATTERN}</pattern>
<!--<pattern>%JsonOutPut %n</pattern>-->
</encoder>
</appender>
<!-- Filter the message level according to the log file generated every day -->
<appender name="FILE_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- The filename of the log file output -->
<FileNamePattern>${FILE_NAME}_err.txt</FileNamePattern>
<!-- Log file retention days -->
<MaxHistory>7</MaxHistory>
<totalSizeCap>512MB</totalSizeCap>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${PATTERN}</pattern>
<!--<pattern>%JsonOutPut %n</pattern>-->
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- Set filter level -->
<level>ERROR</level>
<!-- Processing methods above filter level -->
<onMatch>ACCEPT</onMatch>
<!-- Processing methods below the filter level -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- Generate per day HTML Log files -->
<appender name="FILE_HTML" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- The filename of the log file output -->
<FileNamePattern>${FILE_NAME}_all.html</FileNamePattern>
<!-- Log file retention days -->
<MaxHistory>7</MaxHistory>
<totalSizeCap>512MB</totalSizeCap>
</rollingPolicy>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.html.HTMLLayout">
<pattern>%d{
yyyy-MM-dd HH:mm:ss.SSS}%-5level%thread%c{
50}%M%L%m</pattern>
</layout>
</encoder>
</appender>
<!-- Asynchronous log -->
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<!-- Specify the logs that need to be printed asynchronously -->
<appender-ref ref="FILE" />
</appender>
<!-- Log output level -->
<root level="INFO">
<appender-ref ref="FILE_HTML"/>
<appender-ref ref="FILE_ERROR"/>
<appender-ref ref="FILE"/>
<appender-ref ref="STDOUT"/>
</root>
</configuration>
6.application.yml
logging:
config: classpath:logback.xml
7.logback.xml Replace with desensitized class
①ConsoleAppender - Console desensitization
// Primitive class
ch.qos.logback.core.ConsoleAppender
// Replace class
pers.liuchengyin.logbackadvice.LcyConsoleAppender
②RollingFileAppender - Scrolling files
// Primitive class
ch.qos.logback.core.FileAppender
// Replace class
pers.liuchengyin.logbackadvice.LcyFileAppender
③FileAppender - file
// Primitive class
ch.qos.logback.core.FileAppender
// Replace class
pers.liuchengyin.logbackadvice.LcyFileAppender
Replace example :
<!-- Console output -->
<!-- Console output -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${PATTERN}</pattern>
</encoder>
</appender>
Replace
<appender name="STDOUT" class="pers.liuchengyin.logbackadvice.LcyConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${PATTERN}</pattern>
</encoder>
</appender>
8. test
@SpringBootApplication
@Slf4j
public class LogApplication {
public static void main(String[] args) {
SpringApplication.run(LogApplication.class , args);
log.info("your email:{}, your phone:{}", "[email protected]","15310763497");
log.info("your name:{}", " Jay Chou ");
log.info("your password:{}" , "15310763497");
log.info("your identity:{}", "4408821777708052456");
log.info("your identity:{}", "440882199910");
}
}
9.demo structure

10.gitee Address
https://gitee.com/xulehuang/example/tree/master/log-tuo-min
11. Reference resources
12. Resource upload
边栏推荐
猜你喜欢

cut,sort,uniq,xargs

Shell notes

焱融科技入选北京市 2022 年度“专精特新”,领航混合云文件存储

Scope and lifecycle of beans
![[face recognition] face recognition based on histogram histogram with matlab code](/img/a6/ae776d084a207647501ca951e32000.png)
[face recognition] face recognition based on histogram histogram with matlab code

gradle入门笔记

ETCD数据库源码分析——etcdserver bootstrap从快照中恢复store

sql server建表时设置ID字段自增 (navicat 演示)

Dynamic memory management

【Port 3000 is already in use,3000端口被占用问题解决方法】
随机推荐
vscode下载历史版本
Exchange array elements without creating temporary variables
Dynamic memory management
Left connection query of Android database
SQL优化
QT串口通信
Programming in the novel [serial 14] the moon bends in the yuan universe
[Hongke] lidar safety system: making the world safer
Jsp+Ajax+Servlet+Mysql实现增删改查(一)
Encapsulation API, request interception, response interception, authentication timeliness
Jsp+servlet+mysql案例
Qprocess of QT
gradle入门笔记
ETCD数据库源码分析——etcdserver bootstrap从快照中恢复store
MySQL索引(二)
MySQL initialization and password modification
Markdown(5):锚链接
What is memory overflow
分布式事务-可靠消息最终一致性解决方案
二进制安装 mysql 初始化密码问题