logback身份证脱敏
Posted stono
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了logback身份证脱敏相关的知识,希望对你有一定的参考价值。
logback身份证脱敏
学习了:https://shift-alt-ctrl.iteye.com/blog/2425469
https://blog.csdn.net/fywfengyanwei/article/details/78484590
java:
package com.util; import ch.qos.logback.classic.pattern.MessageConverter; import ch.qos.logback.classic.spi.ILoggingEvent; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ComplexMessageConverter extends MessageConverter { @Override public String convert(ILoggingEvent event) { String source = event.getFormattedMessage(); if (source == null || source.isEmpty()) { return source; } // 身份证号码脱敏 String card = "([1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx])|" + "(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3})"; Pattern p = Pattern.compile(card); Matcher matcher = p.matcher(source); source = matcher.replaceAll("idCardNo"); return source; } }
logback.xml:
<conversionRule conversionWord="m" converterClass="com.util.ComplexMessageConverter"></conversionRule>
以上是关于logback身份证脱敏的主要内容,如果未能解决你的问题,请参考以下文章