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

前端 未结 7 763
小蘑菇
小蘑菇 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:13

    Late entry!

    As I am likely to be searching for this in the future.

    There is a way to create copy/paste friendly Logger instances (granted this is almost never a good reason to do something!) by using Java 7's MethodHandles class.

    private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
    

提交回复
热议问题