Why calling LoggerFactory.getLogger(…) every time is not recommended?

前端 未结 11 2232
借酒劲吻你
借酒劲吻你 2020-12-24 01:07

I\'ve read tons of posts and documents (on this site and elsewhere) pointing that the recommended pattern for SFL4J logging is:

public class MyClass {
    fi         


        
11条回答
  •  -上瘾入骨i
    2020-12-24 01:42

    I just have to say that the recommended pattern is easiest to read and implement. I see no reason for straying from it. Especially no benefit.

    However, my main point is about the guards mentioned previously. I would not recommend explicitly guarding your logs as this is already done internally by log4j and is a duplication of effort.

    Download the source for log4j and have a look at the Logger and Category classes to see for yourself.

提交回复
热议问题