我正在按照 阿帕奇。我遇到了 Log4j1 的 LocationInfo 类,现在我不确定如何调整代码以适应 Log4j2。我检查了 Log4j2 API 和实现中是否有具有该名称的类。不幸的是没有任何成功。此外,指南或我在网站上检查的其他任何地方都没有提到这个问题。任何人都知道如何解决它?
I'm migrating a large application from Log4j 1 to Log4j 2 following the guide of Apache. I came across the usage of Log4j1's LocationInfo class and now I'm not sure how to adjust the code to fit Log4j2. I checked the Log4j2 API and Implementation for a class with that name. Unfortunately without any success. Furthermore this problem is not mentioned by the guide or anywhere else I checked on the site. Anyone has an idea how to solve it?
发布评论
评论(1)
Log4j 2.x Core 中未使用
LocationInfo
类,因为标准 JavaStackTraceElement
代替。当然,它仍然存在于 Log4j 1.x Bridge 中(参见 javadoc)。要检索 StackTraceElement,只需调用
LogEvent#getSource()
。请注意,检索位置信息是一项昂贵的操作,因此如果需要,会延迟执行。默认情况下,
AsyncLogger
不会检索它。A
LocationInfo
class is not used in Log4j 2.x Core, since the standard JavaStackTraceElement
is used instead. Of course it is still present in the Log4j 1.x Bridge (cf. javadoc).To retrieve the
StackTraceElement
, just callLogEvent#getSource()
.Be aware that retrieving location information is an expensive operation, therefore it is performed lazily if needed.
AsyncLogger
s by default don't retrieve it.