log4j: abbreviate/shorten package names

后端 未结 2 414
别那么骄傲
别那么骄傲 2021-01-30 05:01

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.M

2条回答
  •  余生分开走
    2021-01-30 05:46

    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.

    From the javadoc

    ... For example, for the category name "alpha.beta.gamma" the pattern %c{2} will output the last two elements ("beta.gamma"), %c{-2} will remove two elements leaving "gamma", %c{1.} will output "a.b.gamma" ...

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

提交回复
热议问题