Record the execution of each method

Is there a way that I can write / write / control / view every method execution inside a Java program.

For instance:

12:30:12 someMethod("argument")
12:30:12 anotherMethos(1, 2, 3)
12:30:13 finalMethod("invalidInputHere1234")
+5
source share
5 answers

The simple answer is: change the method and insert the entries.

A slightly more complex answer that works even if you cannot change the method: look at aspect programming.

+3
source

Without changing the code, you can use a debugger or profiler that can record any state change, such as a chronometric time debugger .

+2
source
+2
source

You can record your program and then play it with Chronon

+1
source

You can use the @Loggableannotation from jcabi-aspects , which wraps all the methods you want to debug, using a simple logging mechanism:

@Loggable(Loggable.DEBUG)
public String load(URL url) {
  return url.openConnection().getContent();
}

It is registered through SLF4J .

0
source

All Articles