log4j: abbreviate/shorten package names

后端 未结 2 417
别那么骄傲
别那么骄傲 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 05:32

    Artifactory uses Logback:

    Projects known to rely on logback:

    • [...]

    • Artifactory

    which has this nice feature called Conversion Word:

    |Conversion specifier | Logger name                | Result                    |
    |---------------------|:--------------------------:| -------------------------:|
    |%logger              | mainPackage.sub.sample.Bar | mainPackage.sub.sample.Bar|
    |%logger{0}           | mainPackage.sub.sample.Bar | Bar                       |
    |%logger{5}           | mainPackage.sub.sample.Bar | m.s.s.Bar                 |
    |%logger{10}          | mainPackage.sub.sample.Bar | m.s.s.Bar                 |
    |%logger{15}          | mainPackage.sub.sample.Bar | m.s.sample.Bar            |
    |%logger{16}          | mainPackage.sub.sample.Bar | m.sub.sample.Bar          |
    |%logger{26}          | mainPackage.sub.sample.Bar | mainPackage.sub.sample.Bar|
    

    * I miss tables in SO markdown sooo much...

提交回复
热议问题