0

I have put a constraint on a field like so:

import javax.validation.constraints.Pattern;

@Pattern(regexp=SOME_REGEX)
private String someField;

The regex is working correctly, but in the case of an invalid value, the value is getting logged:

[Field error in object 'containingSomeField' on field 'someField': rejected value [InvalidValue123];

Is there a way to disable this logging in annotations? I have not been able to find anything thus far.

I do not want to disable logging in general, just the printing of this value. Masking the value would suffice.

EDIT:

Found the answer to my own question. You can override the default exception handler:

@ControllerAdvice
public class ResponseExceptionHandler extends ResponseEntityExceptionHandler {
 
  @Override
  public final ResponseEntity<Object> handleMethodArgumentNotValid(
      MethodArgumentNotValidException ex,
      @NonNull HttpHeaders headers,
      @NonNull HttpStatus status,
      @NonNull WebRequest request
  ) {
    // Your code here
  }
}
Nad97
  • 3
  • 2

1 Answers1

0

I think, you can configured specific log level for javax.validation through property log4j.logger.org.hibernate.validator (How to turn of hibernate-validator DEBUG logger). For dev env you can set debug level and for prod - error.

saver
  • 2,541
  • 1
  • 9
  • 14