How does slf4j bind to the Logging Framework

AgentX

I was going through the slf4j code to understand the binding process when I stumbled upon the bind() method in the LoggerFactory class

Code snippet of lines of interest:

        if (!isAndroid()) {
            staticLoggerBinderPathSet = findPossibleStaticLoggerBinderPathSet();
            reportMultipleBindingAmbiguity(staticLoggerBinderPathSet);
        }
        // the next line does the binding
        StaticLoggerBinder.getSingleton();
        INITIALIZATION_STATE = SUCCESSFUL_INITIALIZATION;
        reportActualBinding(staticLoggerBinderPathSet);
        replayEvents();

The method findPossibleStaticLoggerBinderPathSet() is something like this:

private static String STATIC_LOGGER_BINDER_PATH = "org/slf4j/impl/StaticLoggerBinder.class";
try {
        ClassLoader loggerFactoryClassLoader = LoggerFactory.class.getClassLoader();
        Enumeration<URL> paths;
        if (loggerFactoryClassLoader == null) {
            paths = ClassLoader.getSystemResources(STATIC_LOGGER_BINDER_PATH);
        } else {
            paths = loggerFactoryClassLoader.getResources(STATIC_LOGGER_BINDER_PATH);
        }

Since the default slf4j-api package provides a class with name StaticLoggerBinder with some defaults and depends on the actual implementations provided by the Binding Projects (log4j, logback etc.).

How does it actually identify which StaticLoggerBinder class to use?

user140547

Well, StaticLoggerBinder is in the source of slf4j-api, but it is removed so it does not end up in the jar. If you download the JAR, you will see it is not there.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to integrate SLF4J logging with Spring 4?

From Dev

how to deal with logging in production code (logback/slf4j)

From Dev

How to retain slf4j MDC logging context in CompletableFuture?

From Dev

Logging with slf4j and any other logging framework (log4j/java.util.logging)

From Dev

Changing log files location dynamically with SLF4J and independently of logging framework

From Java

How to intercept SLF4J (with logback) logging via a JUnit test?

From Dev

how to log in tomcat using slf4j and java.util.logging

From Dev

How to map levels of java.util.logging and SLF4J logger?

From Dev

How to find out, which backend is used for slf4j logging, in third-party library?

From Dev

How do I get logging output in IntelliJ using slf4j in my Gradle project?

From Dev

How to fix "Could not find necessary SLF4j logging jars" with Jetty?

From Dev

How do I get logging output in IntelliJ using slf4j in my Gradle project?

From Dev

Logging in AWS Lambda with slf4j

From Dev

SLF4J logging issue

From Dev

Jclouds logging with SLF4j + log4j instead of SLF4J + logback

From Dev

How to use log4j 2.1.0 over slf4j 1.7.7 in Eclipse RCP? Getting "ERROR StatusLogger Log4j2 could not find a logging implementation."

From Dev

OSGi slf4j logging in Apache Sling/felix

From Dev

logging hibernate parameter values using logback and slf4j

From Dev

SLF4J logging with jboss/wildfly 10

From Dev

Can I turn off logging in SLF4J SimpleLogger?

From Dev

Spring Integration logging error channel (slf4j + logback)

From Dev

Guice Jersey slf4j - request id logging

From Dev

slf4j decorator is logging the decorator FQCN, not the calling FQCN

From Dev

SLF4J - Logging to different files based on a tag

From Dev

OSGi slf4j logging in Apache Sling/felix

From Dev

Why logging via slf4j will lead to starvation?

From Dev

slf4j/logback - disable console logging

From Dev

How is slf4j a facade?

From Dev

How to disable slf4j in jetty

Related Related

  1. 1

    How to integrate SLF4J logging with Spring 4?

  2. 2

    how to deal with logging in production code (logback/slf4j)

  3. 3

    How to retain slf4j MDC logging context in CompletableFuture?

  4. 4

    Logging with slf4j and any other logging framework (log4j/java.util.logging)

  5. 5

    Changing log files location dynamically with SLF4J and independently of logging framework

  6. 6

    How to intercept SLF4J (with logback) logging via a JUnit test?

  7. 7

    how to log in tomcat using slf4j and java.util.logging

  8. 8

    How to map levels of java.util.logging and SLF4J logger?

  9. 9

    How to find out, which backend is used for slf4j logging, in third-party library?

  10. 10

    How do I get logging output in IntelliJ using slf4j in my Gradle project?

  11. 11

    How to fix "Could not find necessary SLF4j logging jars" with Jetty?

  12. 12

    How do I get logging output in IntelliJ using slf4j in my Gradle project?

  13. 13

    Logging in AWS Lambda with slf4j

  14. 14

    SLF4J logging issue

  15. 15

    Jclouds logging with SLF4j + log4j instead of SLF4J + logback

  16. 16

    How to use log4j 2.1.0 over slf4j 1.7.7 in Eclipse RCP? Getting "ERROR StatusLogger Log4j2 could not find a logging implementation."

  17. 17

    OSGi slf4j logging in Apache Sling/felix

  18. 18

    logging hibernate parameter values using logback and slf4j

  19. 19

    SLF4J logging with jboss/wildfly 10

  20. 20

    Can I turn off logging in SLF4J SimpleLogger?

  21. 21

    Spring Integration logging error channel (slf4j + logback)

  22. 22

    Guice Jersey slf4j - request id logging

  23. 23

    slf4j decorator is logging the decorator FQCN, not the calling FQCN

  24. 24

    SLF4J - Logging to different files based on a tag

  25. 25

    OSGi slf4j logging in Apache Sling/felix

  26. 26

    Why logging via slf4j will lead to starvation?

  27. 27

    slf4j/logback - disable console logging

  28. 28

    How is slf4j a facade?

  29. 29

    How to disable slf4j in jetty

HotTag

Archive