How does slf4j bind to implementation? Does it really do so during compile time?

后端 未结 6 1698
轮回少年
轮回少年 2021-02-13 03:58

In the documentation for slf4j it says that the binding happens during complie time:

\"SLF4J does not rely on any special class loader machinery. In fact, each SLF4J bi

6条回答
  •  别跟我提以往
    2021-02-13 04:10

    It's just as @Rad said.

    What I wanna replenish is that if you have multiple StaticLoggerBinder implements in your runtime environment, slf4j choose one of them RANDOMLY, as said in multiple_bindings:

    The way SLF4J picks a binding is determined by the JVM and for all practical purposes should be considered random. As of version 1.6.6, SLF4J will name the framework/implementation class it is actually bound to.

    Another attention is that if your project is planned to be a library for other projects, only slf4j-api should be included, any implementation for slf4j-api is not allowed:

    Embedded components such as libraries or frameworks should not declare a dependency on any SLF4J binding but only depend on slf4j-api. When a library declares a compile-time dependency on a SLF4J binding, it imposes that binding on the end-user, thus negating SLF4J's purpose.

提交回复
热议问题