LoggerFactory.getLogger(ClassName.class) vs LoggerFactory.getLogger(this.getClass().getName())

前端 未结 7 750
小蘑菇
小蘑菇 2021-02-04 00:48

I\'m trying to improve my optimization skills in Java. In order to achieve that, I\'ve got an old program I made and I\'m trying my best to make it better. In this program I\'m

7条回答
  •  走了就别回头了
    2021-02-04 01:09

    When in static context you can't use LoggerFactory.getLogger(getClass()) OR LoggerFactory.getLogger(this.getClass().getName())

    And then you have to use LoggerFactory.getLogger(ClassName.class)

    Anyways I prefer Lombok's @Log4j2 , less code and does the job : https://projectlombok.org/api/lombok/extern/log4j/Log4j2.html

提交回复
热议问题