I use log4j2 in my Spring Boot project. When log event happens I want to mask sensitive data in my DTO using annotation, for example:
@Sensitive(fields = {password, email})
public class MyDTO {
private String name;
private String email;
private String password
}
I want to have opportunity to set fields to mask in annotation props.
I tried to use custom serialiser for this, but I do not want to mask data every time when I serialise my DTO, only when logging event happens.
I tried to apply RewritePolicy, but in this case I already have logging message as String and I can't access class to grab annotation params to know what fields should be masked.
It would be grate to handle log event before myDto.toString() method invoked, get annotation from class, check fields to mask and replace them before set log message.
Could you please help me?