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

前端 未结 11 2236
借酒劲吻你
借酒劲吻你 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:42

    The logger objects are surely reused, so no extra instantation is going to happen either way. The bigger problem I see is that your file/line number info will be useless, since the logger will always faithfully log that each message was issued from class LoggerWrapper, line 12 :-(

    OTOH SLF4J is already a wrapper facade to hide the specific logging framework used, allowing you to freely change between different logging implementations. Therefore I see absolutely no point in hiding that behind yet another wrapper.

提交回复
热议问题