[英]SLF4J logging with jboss/wildfly 10
I have a Java webapp running in a WildFly 10 server.我有一个在 WildFly 10 服务器上运行的 Java webapp。 I used to have the following libraries as Maven dependencies:我曾经有以下库作为 Maven 依赖项:
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
I would now like to use wildfly's builtin logging subsystem.我现在想使用 Wildfly 的内置日志记录子系统。
Currently, it isn't working and I'm not sure which of the 3 steps have I have misconfigured.目前,它不起作用,我不确定我配置错误的 3 个步骤中的哪一个。 Here's a snippet from standalone.xml:这是standalone.xml 中的一个片段:
...
<logger category="com.company">
<level name="DEBUG"/>
</logger>
<root-logger>
<level name="DEBUG"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
...
What you have in your standalone.xml
is correct. 您在standalone.xml
是正确的。 However you're including too many slf4j dependencies. 但是,你包含太多的slf4j依赖项。 slf4j is meant to be a logging facade first. slf4j首先是一个日志记录。 There is no need to include implementation dependencies in your application. 您的应用程序中不需要包含实现依赖项。
First you'll want to remove the log4j2 dependencies from your pom. 首先,您需要从pom中删除log4j2依赖项。 Then mark the org.slf4j:slf4j-api
as <scope>provided</scope>
as the container already provides that dependency for you. 然后将org.slf4j:slf4j-api
标记为<scope>provided</scope>
因为容器已经为您提供了依赖关系。 That should be all you need to do. 这应该就是你需要做的。
I know it's a bit late for the answer, but maybe it helps someone.我知道答案有点晚了,但也许它可以帮助某人。
Ran into the same problem using WildFly 25.0.0.使用 WildFly 25.0.0 遇到了同样的问题。
Solution: Create a file in your war archive in folder "META-INF" named "jboss-deployment-structure.xml" and specify which modules should be excluded from the classpath:解决方案:在您的战争档案中创建一个名为“jboss-deployment-structure.xml”的文件夹“META-INF”中的文件,并指定应从类路径中排除哪些模块:
<jboss-deployment-structure>
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
<exclusions>
<module name="org.slf4j" />
<module name="org.slf4j.impl" />
</exclusions>
</deployment>
</jboss-deployment-structure>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.