Uploaded image for project: 'SLF4J'
  1. SLF4J
  2. SLF4J-386

Multiple Bindings Warning in Tomcat/JavaEE

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Trivial
    • Resolution: Unresolved
    • Affects Version/s: 1.7.x
    • Fix Version/s: None
    • Component/s: Core API
    • Environment:

      Tomcat 8

    • Severity:
      enhancement
    • Priority:
      P4

      Description

      We have a situation where SLF4J is being used in a tomcat container level valve, as well as inside the web applications.

      So specifically we have:

      CATALINA_HOME/lib/log4j-slf4j-impl-.jar - used for container level valves. Unfortunately it must be placed here, because the valves don't come packaged the jar, and log4j2 is being used for the container level logs.

      CATALINA_BASE/webapps/<some_webapp>/WEB-INF/lib/log4j-slf4j-impl-<>.jar - many web developers use slf4j inside their web applications, with log4j2 for their app level logs, which may or may not be the same version as in CATALINA_HOME.

      When starting tomcat an error from standard err shows up saying there are multiple slf4j bindings in the classpath. The problem here is that the slf4j-api.jar used for the container can't be hidden from the web applications, but tomcat (and many other J2EE containers) loads the jars inside the webapp before loading the container level jars. So while is true that there are multiple slf4j bindings on the classpath, the correct one will be evaluated in this case, and there is no issue. However if for some reason the developer of the webapp had multiple slf4j jars inside their webapp, it would be arbitrary which one loads, and thus the warning would be useful.

      A possible solution could be to allow a system property, context param, or something else, that identifies the app as a tomcat or other servlet based webapp, and if it is, only warn the user of multiple slf4j bindings if the bindings are in the webapp's WEB-INF/lib or WEB-INF/classes dirs.

      Also, I would be happy to make the changes, provided the community agrees with the solution. It looks straight forward to place them in: https://github.com/qos-ch/slf4j/blob/master/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java#L292

        Attachments

          Activity

            People

            Assignee:
            slf4j-dev SLF4J developers list
            Reporter:
            dvincent1337 David Vincent
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: