I am trying to replace multiple values in logback logger which logs Cassandra CQL statements and used example from this post: Mask sensitive data in logs with logback
where invocation of %replace function is used:
%replace( %replace(%msg){'regex1', 'replacement1'} ){'regex2', 'replacement2'}
In my case I want to replace 3 fields - name, last name and password. Statement used is:
%replace(%replace(%replace(%msg){"first_name='.*'", "first_name='xxxxx'"}){"last_name='.*'", "last_name='yyyyyy'"}){"password='.*'", "password='zzzzzz'"}%n
It seemed to work ok, but I noticed that if order of fields is different, values are removed sometimes. For example,
1) when statement is in this order it is ok:
Executed:
UPDATE usertest.users SET password='secret_pw', last_name='Smith', first_name='John' where user_id = 1745;
Logged:
UPDATE usertest.users SET password=zzzzzz, last_name=yyyyyy, first_name=xxxxx where user_id = 1745;
2) In this case last name is removed
Executed:
UPDATE usertest.users SET password='secret_pw', first_name='John', last_name='Smith' where user_id = 1745;
Logged:
UPDATE usertest.users SET password=zzzzzz, first_name=xxxxx where user_id = 1745;
3) In this case password is removed
Executed:
UPDATE usertest.users SET last_name='Smith', password='secret_pw', first_name='John' where user_id = 1745;
Logged:
UPDATE usertest.users SET last_name=yyyyyy, first_name=xxxxx where user_id = 1745;
Could someone advice why it could happen and how it could be fixed or is there any other way to solve?