org.zodiac.monitor.logging.mask.ParameterMaskLogger Maven / Gradle / Ivy
package org.zodiac.monitor.logging.mask;
import org.zodiac.monitor.logging.MonitorPreLogger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
public class ParameterMaskLogger implements MonitorPreLogger {
// @Autowired
private LogMask logMask;
// @Autowired
private TextMask textMask;
@Override
public String getLogContent(ProceedingJoinPoint proceedingJoinPoint) {
MethodSignature methodSignature = (MethodSignature)proceedingJoinPoint.getSignature();
Object[] argValues = proceedingJoinPoint.getArgs();
String[] argNames = methodSignature.getParameterNames();
StringBuilder logContent=new StringBuilder();
for (int i = 0; i < argNames.length; i++) {
logContent.append(argNames[i]).append("=");
if(logMask.getShields().containsKey(argNames[i])){
// 方法参数需要遮掩的,先用toString转换为字符串再做遮掩
logContent.append(textMask.mask(argValues[i].toString()));
}else {
// 如果参数名不是需要遮掩的,则作为对象处理,看是否有字段需要遮掩
logContent.append(logMask.maskObject(argValues[i]));
}
logContent.append(", ");
}
return logContent.toString();
}
public LogMask getLogMask() {
return logMask;
}
public void setLogMask(LogMask logMask) {
this.logMask = logMask;
}
public TextMask getTextMask() {
return textMask;
}
public void setTextMask(TextMask textMask) {
this.textMask = textMask;
}
}