log4j:缩写/缩短包名 [英] log4j: abbreviate/shorten package names

查看:3356
本文介绍了log4j:缩写/缩短包名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在使用log4j生成的日志中缩写/缩短包名称。即代替 com.longpackage.anotherpackage.lastpackage.MyClass 我想要 c.l.a.l.MyClass 。我在 Artifactory 日志中看到了这一点,但无法确定如何使用log4j实现此目的。

How would i abbreviate/shorten package names in log generated using log4j. i.e. instead of com.longpackage.anotherpackage.lastpackage.MyClass i want c.l.a.l.MyClass. I have seen this in Artifactory logs, but can't figure how to achieve this using log4j.

推荐答案

事实证明,毕竟使用log4j是可行的(使用 v1.2.16 ),感谢 Tomasz Nurkiewicz 指的是 LogBack 。特征,ConversionWord,可使用 EnhancedPatternLayout 布局。

It turns out that this is possible using log4j after all(tested using v1.2.16), thanks to Tomasz Nurkiewicz for pointing me to LogBack. The feature, ConversionWord, is available using the EnhancedPatternLayout layout.

来自javadoc

...例如,对于类别名称alpha.beta.gamma模式%c {2}将输出最后两个元素(beta.gamma),%c {-2}将删除两个元素,留下gamma,%c {1。将输出abgamma...

我正在使用JBoss并且必须升级log4j并使用上面的布局。

I'm using JBoss and had to upgrade log4j and use the above layout.

这篇关于log4j:缩写/缩短包名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆