1

What is the best practice at the time implementing logging in a Spring MVC REST app?

I understand it is important not to overload application with too much logging. That is why I'm trying to decide wether to have it at service or controller level. Would you advice performing logging at your service level or at controller level or both? If so, why?

megalucio
  • 5,051
  • 2
  • 22
  • 26

1 Answers1

2

The point is to log the important actions of your system, which will allow you to see what's going on later (sometime you don't have anything except logs), but not some certain layer of your application.

Service and Controller have different responsibilities - service works with business logic, while controller is responsible for all web stuff (handling request, call the services for any logic, return response to client). Thus you need to log both layers but with different purposes.

As for the logging levels, there's a good answer here Logging levels - Logback - rule-of-thumb to assign log levels

Community
  • 1
  • 1
ikryvorotenko
  • 1,393
  • 2
  • 16
  • 27