我正在尝试在我的spring boot应用程序中配置log4j2。如果日志中有一些“高度敏感”,“敏感”和“机密”数据,例如令牌,电话号码,电子邮件,它们是动态的,还有一些静态单词(如名字,姓氏,授权),我不想记录味精。 下面是我的配置
Configuration:
status: info
name: log4j2YAMLConfig
ThresholdFilter:
level: info
# filter out "Highly Sensitive", "Sensitive", and "Confidential" data
RegexFilter:
regex: "(?si).*(Bearer|Authorization: Basic|X-Api-Key|X-Auth|Cookie|firstName|lastName|taxId|phone|email).*"
onMatch: "DENY"
onMismatch: "NEUTRAL"
useRawMsg: true
appenders:
RollingFile:
name: fileAppender
fileName: "/app/logs/my-admin-web=${env:xxx}.log"
filePattern: "/app/logs/my-admin-web-${env:xxx}-%i.log"
bufferedIO: false
PatternLayout:
Pattern: "DateTime=%d{ISO8601}{GMT} Application=my-admin-web-${env:xxx} Thread=[%.30t] Logger=%c Type=%p RequestInfo=%X Message=%m%n"
Policies:
SizeBasedTriggeringPolicy:
size: "1 MB"
Loggers:
Root:
level: info
AppenderRef:
-
ref: fileAppender
level: debug
-
ref: fileAppender
level: info
-
ref: fileAppender
level: warn
-
ref: fileAppender
level: error
Logger:
-
name: com.home.www.abc.travel.admin.web.controllers.InvoiceController.successfulPayment
additivity: false
level: info
AppenderRef:
-
ref: fileAppender
level: debug
-
ref: fileAppender
level: info
-
ref: fileAppender
level: warn
-
ref: fileAppender
level: error
我尝试过
RegexFilter:
regex: "(?si).*(Bearer|Authorization: Basic|X-Api-Key|X-Auth|Cookie|firstName|lastName|taxId|phone|email).*"
onMatch: "DENY"
onMismatch: "NEUTRAL"
useRawMsg: true
但是,这只会过滤出与正则表达式匹配的单词(如果它在日志中),而不是实际的电子邮件地址。
尝试过这个也没有用:(
regex: ".*^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$.*"