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

前端 未结 11 2257
借酒劲吻你
借酒劲吻你 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条回答
  •  悲哀的现实
    2020-12-24 01:26

    As stated here by the SLF4J team you can use MethodLookup() introduced in JDK 1.7.

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

    This way you can refer to the class without the need of using the keyword "this".

提交回复
热议问题