Reputation: 103
How can we modify and log request payload in Spring-boot?
I have already implemented CommonsRequestLoggingFilter and am able to log the payload but want to modify the request before being logged so I can hide some sensitive data in the log.
Upvotes: 5
Views: 2734
Reputation: 3762
CommonsRequestLoggingFilter
inherits from AbstractRequestLoggingFilter
which allows you to supply a predicate that should return true
in order to log the error.
In my case, I wanted to log all except the authorization header:
loggingFilter.setHeaderPredicate(header -> !header.toLowerCase().equals("authorization"));
This will result in the logger masking the auth header:
... headers=[authorization:"masked", ...]
Upvotes: 7