简体   繁体   English

如何从.jar文件中获取日志?

[英]How to get logs from a .jar file?

I have an abc.jar file and it has some Java classes in it. 我有一个abc.jar文件,里面有一些Java类。 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? 我想得到调试时遇到的类/方法的日志。我怎么能这样做?

PS - I could have used log4j for it but I don't have the source code. PS - 我本可以使用log4j ,但我没有源代码。

You need to use a profiling tools such as Java's hprof . 您需要使用分析工具,例如Java的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) 对于hprof,CPU使用率采样配置文件的模式(cpu = samples)

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

and CPU Usage Times Profile (cpu=times) 和CPU使用时间配置文件(cpu =次)

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. 这是调试用于给定日志不是一个选项。

You state in your comment that you know that abc.jar doesn't use any logging framework. 您在评论中说明您知道abc.jar不使用任何日志记录框架。

In that case, it is impossible to get logs from it. 在这种情况下,不可能从中获取日志。

However, what you can do is use a debugger. 但是,您可以使用调试器。 All IDEs have debuggers. 所有IDE都有调试器。 This can help you know the state of the classes being called when you use them. 这可以帮助您了解使用它们时调用的类的状态。

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. 假设您有abc.jar,并且它没有使用任何框架进行日志记录,并且您没有任何源代码,如您所述。 No, you can't get logs this way. 不,你不能这样得到日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM