Why do we declare Loggers static final?

后端 未结 14 2009
陌清茗
陌清茗 2020-11-28 01:19

In Java, why is it best practice to declare a logger static final?

private static final Logger S_LOGGER
14条回答
  •  無奈伤痛
    2020-11-28 01:43

    Because that is usually the kind of functionnality that can be shared accross all instances of your objects. It does not make much sense (90% of the time) to have a different logger for two instances of the same class.

    However, you can also see sometimes logger classes declared as singletons or even simply offering static functions to log your stuff.

提交回复
热议问题