Mask, Hide & Replace Sensitive Data In Spring Boot Logs | Console Appender | Rolling File Appender

preview_player
Показать описание
- - -
Know how to hide or mask or replace sensitive log details printed in JSON or To-String format in the console appender or rollingFile appender using replace (aka %replace expression)
This masking works in both console and rolling-File-Appender. See the complete video to know more.
- - -

The replace expression, Example:
-----------------------------------------------------
Hint# Replace toString data: %replace(%msg){((?i)\bproductName\b(=)\w*),"productName=*******"}
Hint# Replace Json String: %replace(%msg){((?i)"\bsellerName\b(":\w*))"[^"]+",$1"*******"}

#A Sample Input Data:
1. Json Data: {"productId":1, "productName":"p1", "sellerName": "s1"}
2. toString Data: [productId=1, productName="p1", sellerName="s1"]
- - - - -
# Output:
1. Json Data: {"productId":1, "productName":"******", "sellerName": "******"}
2. toString Data: [productId=1, productName="*******", sellerName="******"]
- - -

Development Frameworks & Tools:
#springboot
#postman
#lombok
#slf4j
#log4j
#logging

Feel free to add comments with your suggestions.

~Thank you
Рекомендации по теме
Комментарии
Автор

But this is not very optimal solution. What happens if i have to encrypt some 30 fileds? Logback will parse the same log 30 times before printing?

pvsg
Автор

How to replace only last 3 character, instead of entire text????

tiger
Автор

Hi Codevice, can we create 2 rolling file in same time? one with masking and the other file without masking. I have added two rolling file appender in my logaback file but one rolling file only getting logs and other file is empty.

rameshkanakarajan
Автор

Hello Sir, could you please add regex pattern in description, I couldn't find any

GauravSingh-zlcv
Автор

Please can you share logback.xml file?

sangmeshwarrajure