logback日志敏感字段掩码

背景

继上次log4j2做完日志掩码处理后, 发现其他项目中有用到logback, 于是同样去官网翻了下, 发现基本语法差不多, 不过语法稍微有些差异~

replace(p){r, t}

Replaces occurrences of 'r', a regex, with its replacement 't' in the string produces by the sub-pattern 'p'. For example, "%replace(%msg){'\s', ''}" will remove all spaces contained in the event message.

The pattern 'p' can be arbitrarily complex and in particular can contain multiple conversion keywords. For instance, "%replace(%logger %msg){'\.', '/'}" will replace all dots in the logger or the message of the event with a forward slash.

有个特殊的地方, 就是因为具体的替换规则是写在value里的, 双引号需转义

具体操作贴在下面

<Property name="REGEX" value="%replace(%msg){'&quot;([1-9][0-9]{2})([0-9]{6})([0-9]+|[0-9]+X)', '&quot;$1***$3'}"/>
<property name="ENCODER_PATTERN"
              value="%d{yyyy-MM-dd HH:mm:ss.SSS} [${APP_NAME}] [%thread] %-5level [%logger] %M-${REGEX}%n"/>

结果

logger.info("\"123091023012930129031");
logger.info("1230910230129\"301290313132");

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"123***012930129031
1230910230129"301***132

其他方法自行研究吧~

官网地址: Chapter 6: Layouts

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值