Prevent Weblogic 12c from using system's slf4j binding

dhchen picture dhchen · Mar 16, 2012 · Viewed 23.1k times · Source

We're building new systen using slf4j as logging facade. When deploying on newly Weblogic 12c, we found this error on console log:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/Oracle/Middleware2/modules/org.slf4j.jdk14_1.6.1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [zip:/opt/Oracle/Middleware2/user_projects/domains/m3/servers/AdminServer/tmp/_WL_user/test/t030q4/war/WEB-INF/lib/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]

after googling, we found that this is just a warning, slf4j will bind first found logger, which in this case is weblogic's system logger framework. Is there any way to make it bind to logging framework in our WAR file? Having <prefer-web-inf-classes> in weblogic.xml does not help

Answer

Luca picture Luca · Oct 5, 2012

The filtering should not be done on classes but on resources, because SLF4J looks for the StaticLoggerBinder.class as a resource and not as a class.

Include this in your weblogic-application.xml as well:

<wls:prefer-application-packages>
    <wls:package-name>org.slf4j.*</wls:package-name>
    <wls:package-name>org.apache.commons.*</wls:package-name>
</wls:prefer-application-packages>

<wls:prefer-application-resources>
    <wls:resource-name>org/slf4j/impl/StaticLoggerBinder.class</wls:resource-name>
</wls:prefer-application-resources>

and your logger will be used instead of the one inside the System ClassLoader.