gpt4 book ai didi

java - 我的 Java 记录器(比如 logback)如何找到我的代码的行号?

转载 作者:行者123 更新时间:2023-11-30 06:20:48 25 4
gpt4 key购买 nike

我的 Java 记录器(比如 logback)如何找到我的代码的行号?

这是否是高性能系统中包含文件行号的性能问题?

它是否需要抛出异常并分析堆栈跟踪来执行此操作,还是有其他技巧?

谢谢

最佳答案

行号被编译到 .class 文件中,获取它们肯定比不这样做要多做一些工作。

您可以通过 Thread#getStackTrace() 在不抛出异常的情况下获取堆栈跟踪信息但这应该与创建异常的成本大致相同(您不需要抛出并捕获它)。

How Expensive is Thread.getStackTrace()? 中所述,收集信息可能非常昂贵

但是单独过多的日志记录已经可以大大降低系统的速度。

Is this a performance issue in a high performance system to include the file line number?

你应该测试一下。如果没有行号还不是性能问题,那么很可能没有问题。这完全取决于您登录的位置和频率。


documentation还提到了行号

Generating the line number information is not particularly fast. Thus, its use should be avoided unless execution speed is not an issue.

关于java - 我的 Java 记录器(比如 logback)如何找到我的代码的行号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21306839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com