What's the overhead of creating a SLF4J loggers in static vs. non-static contexts?

后端 未结 2 1260
情话喂你
情话喂你 2020-12-29 04:14

I\'ve always used the following pattern to construct (SLF4J) loggers:

private static final Logger log = LoggerFactory.getLogger(MyClass.class);
2条回答
  •  情话喂你
    2020-12-29 04:57

    I am not sure about the exact overhead when using LoggerFactory but I doubt it will affect your application performance. So simply use static or non static as you see fit.

    What should be the benefit of using @Inject. The LoggerFactory already provides and abstraction from the concrete impl. In any case it will be a lot slower than the LoggerFactory.

    The syntax is more concise when you use @Inject that is true. But imagine you use the class in a test. Then you have to setup the injection to get logging. With the normal LoggerFactory it also works nicely in tests. If java had a generic mechanism for @Inject it would work great but as it is the setup is more difficult.

提交回复
热议问题