6

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") 
2

5 Answers 5

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I want to trace hundreds of methods so can't really change every single one of them. Is there not a way of monitoring the execution of a Java program to see the methods being run? I know that I can use NetBeans to track a variable's value - what about which methods have been executed?
Take a look at this article
2

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.

Comments

2

Try this: https://github.com/taobao/TProfiler

Comments

1

You can record your program and then play it with Chronon

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.