Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/create1st/logback-masked-fields

Logback layout to obscure confidential or secure information
https://github.com/create1st/logback-masked-fields

logback logging

Last synced: about 7 hours ago
JSON representation

Logback layout to obscure confidential or secure information

Awesome Lists containing this project

README

        





# logback-masked-fields
Logback layout to obscure confidential or secure information

Maven
```xml

com.craftandtechnology
logback-masked-fields
1.3.0

```

Gradle
```kotlin
implementation("com.craftandtechnology:logback-masked-fields:1.3.0")
```

Each class containing confidential information should have a dedicated formatter defined and this formatter shall be part of the Logback configuration

Sample argument formatter
```java
public class UserDataFormatter implements ArgumentFormatter {
private final PatternArgumentFormatter patternArgumentFormatter = new PatternArgumentFormatter(CONFIDENTIAL_DATA_REGEX);

@Override
public Class> getSupportedClass() {
return UserData.class;
}

@Override
public Object formatArgument(Object argument) {
return patternArgumentFormatter.formatArgument(argument);
}
}
```

Sample Logback configuration

```xml



%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
com.craftandtechnology.logging.ConfidentialDataFormatter
com.craftandtechnology.logging.UserDataFormatter



```

```Java
public class MaskingPatternLayoutDemoTest {
private final static Logger logger = LoggerFactory.getLogger(MaskingPatternLayoutDemoTest.class);

@Test
void simpleTestOutput() {
logger.info("Test : {}", userData());
}
}
```

```log
11:31:25.878 [Test worker] INFO c.c.MaskingPatternLayoutDemoTest - Test : UserData(confidentialData=ConfidentialData(clientId=*****, clientName=*****), nonConfidentialData=NonConfidentalData(transactionId=someTransactionId, amount=10, transactionDate=2021-04-24))
```