Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logback: replacing 10 digit number by ******** and last two digit

I use the following in my pattern(logback.xml) to replace 10 digit numbers in my log.

%replace(%msg){'\d{10}','**********'}

One problem with this approach is, it also matches first 10 digits of 11 digit number. Is there a way to match exactly 10 digits numbers.

Now the bigger problem is somehow I need to display the last two digits of this 10 digit number.

like image 888
Thomas Avatar asked Jul 31 '14 06:07

Thomas


1 Answers

Use this:

%replace(%msg){'\b\d{10}\b','**********'}

\b is a word boundary that matches a position where one side is a letter, and the other side is not a letter (for instance a space character, or the beginning of the string)

like image 81
zx81 Avatar answered Oct 04 '22 04:10

zx81