3

I want to log some statements in my method using AOP.

I am able to define the pointcuts, advice for method starting, ending, exception scenarios.

Can we log in between the method at some point (after method entry and before execution finishes?) I am using Spring 3.0.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
java_enthu
  • 2,279
  • 7
  • 44
  • 74
  • possible duplicate of [Spring: Standard Logging aspect (interceptor)](http://stackoverflow.com/questions/7302090/spring-standard-logging-aspect-interceptor) – Tomasz Nurkiewicz Oct 28 '11 at 07:28
  • @Tomasz Nurkiewicz: this is not a duplicate of this question, because the problem is how place some logstatement in the middle of the method. This theme is not discussed in the other question. – Ralph Oct 28 '11 at 09:32
  • @java_enthu: My apologies, I misunderstood your question. Unfortunately I can't revert my close vote, but you have my +1 and an answer :-). – Tomasz Nurkiewicz Oct 28 '11 at 09:52

1 Answers1

2

No, it is not possible. Spring is not capable of "looking into" your methods and modifying them. Technically AspectJ weaving can do this, but I would stay away from such approaches.

What you can do is to extract methods, which will not only allow you to provide some finer-grained logging, but you will also improve the overall code quality. However note that by default Spring can only intercept public (proxies) and protected methods (CGLIB).

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674