用于 Java 的基于仪器的日志框架

发布于 2024-12-18 06:07:06 字数 943 浏览 0 评论 0原文

我正在尝试找出我的一个 Java 项目中的问题,目前我面临着必须手动向一大堆方法添加大量日志记录语句的可能性。正如您可能理解的那样,我不太喜欢这个想法:

  • 这些方法中的大多数都是性能关键型的,我宁愿在不需要时不添加日志记录,即使它像 log4j

  • 在某些情况下,我想记录 Java 库中类的操作。虽然 OpenJDK 源代码可用,但我不会为此提供我自己的 Java 库版本。

  • 我有兴趣在特定条件下记录特定代码路径。虽然我可能可以集中日志记录适用性检查,但如果我需要修改条件,我仍然预见到未来会发生不可预见的重构。

  • 添加日志语句en-mass需要大量的工作和时间,我宁愿更高效地使用它们。

考虑到字节码操作库的存在,例如 Javassist 和 < a href="http://commons.apache.org/bcel/" rel="nofollow">BCEL,我希望可能有一个日志框架可以帮助我摆脱繁重的工作。

由于我主要对记录特定条件下的方法调用参数和返回值感兴趣,是否有一个基于检测的 Java 日志框架允许我执行此操作?最好是比 Java 代理

I am trying to track down an issue in one of my Java projects and I am currently facing the possibility of having to manually add a lot of logging statements to a whole bunch of methods. As you can probably understand, I am not very fond of that idea:

  • Most of those methods are performance-critical and I'd rather not add logging when it's not needed, even if it's something as lightweight as log4j.

  • In some cases I'd like to log the operation of classes from the Java library. While the OpenJDK source code is available, I am not going to provide my own Java library version just for this.

  • I am interested in logging specific code paths under specific conditions. While I could probably centralize the logging applicability checks, I still foresee unforeseen refactoring in my future, should I need to modify the conditions.

  • Adding logging statements en-mass requires a lot of work and time, which I'd rather use more productively.

Considering the existence of bytecode manipulation libraries, such as Javassist and BCEL, I was hoping that there might be a logging framework that would take the grunt work out of my hands.

Since I am mainly interested in logging method call arguments and return values under specific conditions, is there an instrumentation-based logging framework for Java that would allow me to do this? Preferably something somewhat more modern and a little less awkward than Java agents?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦亿 2024-12-25 06:07:06

日志记录是面向方面编程的“hello world”。

如果您已经是 Spring 用户,您将能够编写一个方面类来记录您想要的内容,然后将其以声明方式编织到所有需要它的对象中。

Spring有自己的AOP实现;它还支持 AspectJ。

如果您愿意的话,您可以在没有 Spring 的情况下使用 AspectJ。

Logging is the "hello world" of aspect-oriented programming.

If you're already a Spring user, you'll be able to write a single aspect class to log what you want and then weave it declaratively into all the objects that need it.

Spring has its own AOP implementation; it also supports AspectJ.

You can use AspectJ without Spring if that's your preference.

橘味果▽酱 2024-12-25 06:07:06

试试这个开源工具:http://code.google.com/p/perfspy/ 。它是一个运行时日志记录、性能监控和代码检查工具。它使用 ApsectJ 在运行时编织您的应用程序代码,并记录每个方法的执行时间及其输入参数和值。它有一个 UI 应用程序,您可以在其中以树的形式查看方法调用及其输入和返回值。有了它,您可以发现性能瓶颈并了解复杂的代码流程。

Try this open source tool: http://code.google.com/p/perfspy/. It is a runtime logging, performance monitoring and code inspecting tool. It uses ApsectJ to weave around your application code at runtime, and logs the execution time of every method and its input parameters and values. It has a UI application, in which you can view the method invocations and their input and return values as trees. With it, you can spot performance bottlenecks and understand complex code flow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文