Why do we declare Loggers static final?

后端 未结 14 2061
陌清茗
陌清茗 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:42

    Check this blog post: Get Rid of Java Static Loggers. This is how you use slf4j with jcabi-log:

    import com.jcabi.log.Logger;
    class Foo {
      void save(File f) {
        Logger.info(this, "file %s saved successfully", f);
      }
    }
    

    And never use that static noise any more.

提交回复
热议问题