Last active
May 7, 2021 00:42
-
-
Save sandipchitale/ad10e01bfe433ef7050df77f266da1fd to your computer and use it in GitHub Desktop.
Masking layout to redact sensitive info from log messages #logback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configuration> | |
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | |
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> | |
<layout class="com.example.gateway.MaskingPatternLayout"> | |
<Pattern> | |
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n | |
</Pattern> | |
</layout> | |
</encoder> | |
</appender> | |
<root level="INFO"> | |
<appender-ref ref="STDOUT" /> | |
</root> | |
</configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.gateway; | |
import ch.qos.logback.classic.PatternLayout; | |
import ch.qos.logback.classic.spi.ILoggingEvent; | |
public class MaskingPatternLayout extends PatternLayout { | |
private String patternsProperty; | |
public String getPatternsProperty() { | |
return patternsProperty; | |
} | |
public void setPatternsProperty(String patternsProperty) { | |
this.patternsProperty = patternsProperty; | |
} | |
@Override | |
public String doLayout(ILoggingEvent event) { | |
String message = super.doLayout(event); | |
message = message.replace("8080 (http)", "MAMAMAMA"); | |
return message; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment