I am making an http request using Httpclient and I need to hide logs for this specific API call as it contains sensitive data. We need the logs to be in debug level so lowering the log level is not an option is there a way that I can hide the logs of just this request?
public Boolean authenticate(String userName, String password) throws IOException {
HttpPost httpPost = new HttpPost(authServiceBaseUrl + AUTH_SERVICE_AUTH_URI);
try {
StringEntity httpEntity = new StringEntity(new JSONObject()
.put(USERNAME_ATTRIBUTE_NAME, userName)
.put(PASSWORD_ATTRIBUTE_NAME, password)
.toString());
httpEntity.setContentType(ContentType.APPLICATION_JSON.toString());
httpPost.setEntity(httpEntity);
} catch (Exception e) {
throw new Exception(logException(userName, "authenticate"), e );
}
try (CloseableHttpClient httpClient = getHttpClient();
CloseableHttpResponse response = httpClient.execute(httpPost)) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
return Boolean.TRUE;
} else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
log.warnf("[%s] Authentication failed.", userName);
return Boolean.FALSE;
} else {
throw new UserAuthenticationException(
response.getStatusLine().getStatusCode(), userName,
"Error while trying to authenticate user");
}
} catch (UserAuthenticationException e) {
throw e;
} catch (Exception e) {
throw new Exception(logException(userName, "authenticate"), e);
}
}