Is there any way that I can log / record / monitor / view every execution of a method inside of a Java program.
For example:
12:30:12 someMethod("argument")
12:30:12 anotherMethos(1, 2, 3)
12:30:13 finalMethod("invalidInputHere1234")
Is there any way that I can log / record / monitor / view every execution of a method inside of a Java program.
For example:
12:30:12 someMethod("argument")
12:30:12 anotherMethos(1, 2, 3)
12:30:13 finalMethod("invalidInputHere1234")
Easy answer: modify the method, and insert logging statements.
Somewhat more complex answer, which works even if you can't modify the method: look into aspect-based programming.
Without modifying the code you could use a debugger or profiler that is able to record any state change, like the Chronon time travelling debugger.
You can use @Loggable
annotation from jcabi-aspects, which wraps all methods you want to debug with a simple logging mechanism:
@Loggable(Loggable.DEBUG)
public String load(URL url) {
return url.openConnection().getContent();
}
It logs through SLF4J.