I'm new to Java, I have to log enter and exit of function flow, it's quite easy doing it in C++, but I don't know how to do it in Java.
Any input will be appreciated.
Asked
Active
Viewed 1,296 times
5

Simulant
- 19,190
- 8
- 63
- 98

user1808932
- 427
- 1
- 5
- 14
-
Thie topic is really wide, you can google about Instrumentation of Java code. – Damian Leszczyński - Vash Nov 08 '12 at 10:32
-
6How did you do it in C++? What have you tried in Java? Are you familiar with aspects - which is probably what you should try. – Anders R. Bystrup Nov 08 '12 at 10:32
-
Have a look at [Log4j](http://logging.apache.org/log4j/), it might help. – S.L. Barth is on codidact.com Nov 08 '12 at 10:33
-
1IMHO. It's easier in Java than C++ and you can weave additional code at build time or runtime. http://stackoverflow.com/questions/8839077/how-to-use-aop-with-aspectj-for-logging – Peter Lawrey Nov 08 '12 at 10:35
1 Answers
2
There are several logging libraries (log4J http://logging.apache.org/log4j/1.2/ being a commonly used one) and slf4J http://www.slf4j.org/ being particularly useful as it is library agnostic.
If you want to log every function entry/exit you could look at AspectJ/AOP as mentioned in this post How to use AOP with AspectJ for logging?