gpt4 book ai didi

java - Logback 模式相当于 log4j %l

转载 作者:行者123 更新时间:2023-11-30 03:17:46 24 4
gpt4 key购买 nike

配置 log4j 我可以使用 log4j 1.2 pattern %l 给我调用者的位置,输出:

... com.example.FooBar.doSomething(FooBar.java:123) ...

我正在尝试切换到 Logger,因为它是 "intended as a successor"到 log4j 并有 all sorts of improvements超过 log4j 1.2

但是 Logback 没有 %l 模式。最近的Logback pattern我可以找到 %caller{1},但这给了我一些难看的东西:

... Caller+0     at com.example.FooBar.doSomething(FooBar.java:123)
...

请注意,它在我的日志行中间添加了一个换行符,这是对丑陋的侮辱。 (当时我没有在模式中指定换行符。)

如何在 Logback 模式中获得相当于 log4j %l 的内容?

最佳答案

您是正确的,%l 不再存在于 logback 中。这可能是因为,从您自己的文档链接:

The location information can be very useful. However, its generation is extremely slow and should be avoided unless execution speed is not an issue.

不幸的是,你不能用 %caller 做得更好,即使你认为它是 %l 的最佳替代品是正确的。如您所见in the source here ,该换行符非常彻底地嵌入到错误消息生成步骤中。

我希望能为您带来更好的消息,但我认为如果没有custom Layout,您就无法做得更好。 。您可以从以下事实中得到一些小小的安慰: this has been asked before .

<小时/>

我有just submitted a new Feature Request here.

关于java - Logback 模式相当于 log4j %l,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32158409/

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