QQQ
QQQ

Reputation: 59

What is the best way to do logging for REST method call?

What is the best way to do logging for REST method call?

I tryed two ways to log the information of methods like input passed to the method, output of that method, if exception thrown - what exception, which class and method and exception line are logged.

Method1 : Using finally method

Method2 : Using Spring AOP

Which is the best way to do? Is there any other way we can do logging.

Upvotes: 0

Views: 79

Answers (2)

ACV
ACV

Reputation: 10552

finally is for exceptions. AOP looks good if you have many methods. Otherwise just add the LOG statements (in case you're using a logger framework like log4j) where you think you need them. AOP has a slight performance impact.

Upvotes: 2

Anil Kesarwani
Anil Kesarwani

Reputation: 59

I am here adding a point over ACV's suggestion since what ever he has suggested are correct , 1. AOP will be loose couple that give you more flexibility in terms of optional deployment , 2.Your actual business logic and method will be remain neat & clean . no extra line would be appear there. 3.Could use your code for entire application even in other application too.

Upvotes: 1

Related Questions