2

I would like to log something to some Eclipse view after/before specific methods are entered in my Java project.

Is this possible?

  • I don't want it to break to the Debugger, so no breakpoints
  • AspectJ might be a last resort, but can you provide some quick'n'dirty tutorial with it, as it is quite foreign to me

ADDITIONAL INFO 1: I am using Eclipse 4.2

P Varga
  • 19,174
  • 12
  • 70
  • 108

1 Answers1

2

Create a normal breakpoint in the method, add a condition like

System.out.println("hit the method"); return false;

That breakpoint will always be evaluated, but it will not stop the debugger. You can use the same technique also with a method breakpoint (instead of line breakpoint) and there you can additionally specify whether it shall be evaluated on entering or leaving the method.

Bananeweizen
  • 21,797
  • 8
  • 68
  • 88
  • Thanks, that's exactly what I was looking for. Is there a way to get the current method's name in the condition? All I can think of is something like creating a new Exception and getting the method at the top of the stack trace... – P Varga Sep 19 '12 at 18:18
  • 1
    Thread.currentThread().getStackTrace() avoids the costly exception. More alternatives: http://stackoverflow.com/questions/442747/getting-the-name-of-the-current-executing-method – Bananeweizen Sep 20 '12 at 05:12
  • Just for others doing the same: in case of Android, System.out in breakpoint conditionals will go to LogCat! Works great! – P Varga Sep 21 '12 at 10:29