Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
head_group
xyqb-user2
Commits
ebfda018
Commit
ebfda018
authored
May 04, 2017
by
Java-刘 彧阳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
测试日志脱敏
parent
3f3bbde4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
1 deletion
+25
-1
WithOutPhoneLoggingEvent.java
...cn/quantgroup/xyqb/util/log/WithOutPhoneLoggingEvent.java
+25
-1
No files found.
src/main/java/cn/quantgroup/xyqb/util/log/WithOutPhoneLoggingEvent.java
View file @
ebfda018
...
@@ -4,7 +4,11 @@ import ch.qos.logback.classic.Level;
...
@@ -4,7 +4,11 @@ import ch.qos.logback.classic.Level;
import
ch.qos.logback.classic.spi.ILoggingEvent
;
import
ch.qos.logback.classic.spi.ILoggingEvent
;
import
ch.qos.logback.classic.spi.IThrowableProxy
;
import
ch.qos.logback.classic.spi.IThrowableProxy
;
import
ch.qos.logback.classic.spi.LoggerContextVO
;
import
ch.qos.logback.classic.spi.LoggerContextVO
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
org.slf4j.Marker
;
import
org.slf4j.Marker
;
/**
/**
...
@@ -12,6 +16,8 @@ import org.slf4j.Marker;
...
@@ -12,6 +16,8 @@ import org.slf4j.Marker;
*/
*/
public
class
WithOutPhoneLoggingEvent
implements
ILoggingEvent
{
public
class
WithOutPhoneLoggingEvent
implements
ILoggingEvent
{
private
static
Pattern
pattern
=
Pattern
.
compile
(
"(?<!\\d)(?:(?:1[34578]\\d{9})|(?:861[34578]\\d{9}))(?!\\d)"
);
private
ILoggingEvent
event
;
private
ILoggingEvent
event
;
transient
String
withOutPhoneFormattedMessage
;
transient
String
withOutPhoneFormattedMessage
;
...
@@ -41,7 +47,8 @@ public class WithOutPhoneLoggingEvent implements ILoggingEvent {
...
@@ -41,7 +47,8 @@ public class WithOutPhoneLoggingEvent implements ILoggingEvent {
return
withOutPhoneFormattedMessage
;
return
withOutPhoneFormattedMessage
;
}
}
//todo 用正则找到手机号,并打上掩码,替换进去
//todo 用正则找到手机号,并打上掩码,替换进去
withOutPhoneFormattedMessage
=
event
.
getFormattedMessage
().
concat
(
"##test##"
);
//withOutPhoneFormattedMessage = event.getFormattedMessage();
withOutPhoneFormattedMessage
=
coverPhone
(
event
.
getFormattedMessage
());
return
withOutPhoneFormattedMessage
;
return
withOutPhoneFormattedMessage
;
}
}
...
@@ -87,4 +94,21 @@ public class WithOutPhoneLoggingEvent implements ILoggingEvent {
...
@@ -87,4 +94,21 @@ public class WithOutPhoneLoggingEvent implements ILoggingEvent {
// fixes http://jira.qos.ch/browse/LBCLASSIC-104
// fixes http://jira.qos.ch/browse/LBCLASSIC-104
this
.
getMDCPropertyMap
();
this
.
getMDCPropertyMap
();
}
}
private
static
String
coverPhone
(
String
str
){
if
(
str
.
length
()<=
0
)
return
""
;
Matcher
matcher
=
pattern
.
matcher
(
str
);
Map
<
String
,
String
>
replaceMap
=
new
HashMap
<>();
while
(
matcher
.
find
())
{
String
group
=
matcher
.
group
();
String
replace
=
group
.
substring
(
0
,
3
).
concat
(
"****"
).
concat
(
group
.
substring
(
7
));
replaceMap
.
put
(
group
,
replace
);
}
Set
<
Map
.
Entry
<
String
,
String
>>
entries
=
replaceMap
.
entrySet
();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
entries
){
str
=
str
.
replaceAll
(
entry
.
getKey
(),
entry
.
getValue
());
}
return
str
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment