0

We are printing the input params of a method for debug purposes:

 public void findUser(User user, String abc, Date startDate, Date endDate, Integer rpp){
    log.debug("start findUser: user {}, startDate {}, endDate {}, abc{}, rpp {}", user, startDate, endDate, abc, rpp);
    ....

Writing such log messages is very annoying and error-prone.

Is there a way to achieve the same (or similar) log messages without all the manual work?

riorio
  • 6,500
  • 7
  • 47
  • 100
  • Lookup AOP Interceptors. For spring you can find an answer here: https://stackoverflow.com/questions/7302090/spring-standard-logging-aspect-interceptor Similiar stuff can be done with CDI Interceptors. – TomStroemer May 07 '20 at 08:58
  • 2
    Doesn't look *very annoying and error-prone* to me. – akuzminykh May 07 '20 at 09:01
  • @akuzminykh well it is. If you do this for hundrets of methods it's easy to miss or misspell a parameter. And it's easy to forget to change the line when adding new parameters to the method. – TomStroemer May 07 '20 at 09:11

0 Answers0