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: 2 months ago
JSON representation
Logback layout to obscure confidential or secure information
- Host: GitHub
- URL: https://github.com/create1st/logback-masked-fields
- Owner: create1st
- License: apache-2.0
- Created: 2021-04-23T22:05:02.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-17T20:02:23.000Z (over 3 years ago)
- Last Synced: 2026-01-01T01:45:08.590Z (6 months ago)
- Topics: logback, logging
- Language: Java
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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))
```