防止 Weblogic 12c 使用系统的 slf4j 绑定 [英] Prevent Weblogic 12c from using system's slf4j binding

查看:47
本文介绍了防止 Weblogic 12c 使用系统的 slf4j 绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用 slf4j 作为日志外观构建新系统.在新的Weblogic 12c上部署时,我们在控制台日志中发现了这个错误:

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]

google了之后发现这只是一个警告,slf4j会绑定first found logger,这里是weblogic的系统logger框架.有没有办法让它绑定到我们的 WAR 文件中的日志框架?拥有<prefer-web-inf-classes>在 weblogic.xml 中没有帮助

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

推荐答案

过滤不应该在类上进行,而应该在资源上进行,因为 SLF4J 将 StaticLoggerBinder.class 作为资源而不是作为资源进行查找一个班级.

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.

也将其包含在您的 weblogic-application.xml 中:

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.

这篇关于防止 Weblogic 12c 使用系统的 slf4j 绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆