Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get logs from a .jar file?

Tags:

java

logging

jar

I have an abc.jar file and it has some Java classes in it. I don't have the source code of it. I want to get logs of the classes/methods that's been hit while debugging.How can I do that?

P.S - I could have used log4j for it but I don't have the source code.

like image 366
Ravish Rawat Avatar asked Aug 20 '15 09:08

Ravish Rawat


3 Answers

You need to use a profiling tools such as Java's hprof. It is a good introduction to profiling. While not powerful, it is a good start. There are plenty of other useful profiling tools. Just google them.

For hprof, the modes of CPU Usage Sampling Profiles (cpu=samples)

e.g. javac -J-agentlib:hprof=cpu=samples Hello.java 

and CPU Usage Times Profile (cpu=times)

e.g. javac -J-agentlib:hprof=cpu=times Hello.java

sound like what you needs. They can tell you what is called and how often. What they won't tell you is the state of variables. This is what debugging is used for given that logging is not an option.

like image 107
Brett Walker Avatar answered Oct 19 '22 19:10

Brett Walker


You state in your comment that you know that abc.jar doesn't use any logging framework.

In that case, it is impossible to get logs from it.

However, what you can do is use a debugger. All IDEs have debuggers. This can help you know the state of the classes being called when you use them.

like image 4
Olivier Grégoire Avatar answered Oct 19 '22 19:10

Olivier Grégoire


Let's say if you have abc.jar and it doesn't use any framework for logging, and you don't have any source code as you have mentioned. No, you can't get logs this way.

like image 4
Nadim parvej Avatar answered Oct 19 '22 20:10

Nadim parvej