SLF4J 日志记录 jboss/wildfly 10
SLF4J logging with jboss/wildfly 10
我在 WildFly 10 服务器中有一个 Java webapp 运行。我曾经将以下库作为 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>
我现在想使用 wildfly 的内置日志子系统。
- 我需要将哪些库添加到我的项目中?
- 如何配置在 standalone.xml 中声明的默认日志类别和根记录器以记录级别 "debug" 的包 "com.mycompany" 中的所有内容?
- 我 运行 将 wildfly 服务器作为我的 eclipse 中的一个插件。通过使用控制台处理程序,我希望将日志写入 Eclipse
的控制台
目前,它不起作用,我不确定我配置错误的 3 个步骤中的哪一个。这是来自 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>
...
您 standalone.xml
中的内容是正确的。但是,您包含了太多 slf4j 依赖项。 slf4j 首先是一个日志外观。无需在您的应用程序中包含实现依赖项。
首先,您需要从 pom.xml 中删除 log4j2 依赖项。然后将 org.slf4j:slf4j-api
标记为 <scope>provided</scope>
,因为容器已经为您提供了该依赖项。这应该是您需要做的全部。
我知道现在回答有点晚了,但也许它对某人有帮助。
运行 使用 WildFly 25.0.0 遇到同样的问题。
解决方法:
在文件夹“META-INF”中的 war 存档中创建一个名为“jboss-deployment-structure.xml”的文件,并指定应从类路径中排除哪些模块:
<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>
我写在这里:
https://gist.github.com/BlueSKySec/63006f7cd6bef717af0bae71c1e3a9dc
我在 WildFly 10 服务器中有一个 Java webapp 运行。我曾经将以下库作为 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>
我现在想使用 wildfly 的内置日志子系统。
- 我需要将哪些库添加到我的项目中?
- 如何配置在 standalone.xml 中声明的默认日志类别和根记录器以记录级别 "debug" 的包 "com.mycompany" 中的所有内容?
- 我 运行 将 wildfly 服务器作为我的 eclipse 中的一个插件。通过使用控制台处理程序,我希望将日志写入 Eclipse 的控制台
目前,它不起作用,我不确定我配置错误的 3 个步骤中的哪一个。这是来自 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>
...
您 standalone.xml
中的内容是正确的。但是,您包含了太多 slf4j 依赖项。 slf4j 首先是一个日志外观。无需在您的应用程序中包含实现依赖项。
首先,您需要从 pom.xml 中删除 log4j2 依赖项。然后将 org.slf4j:slf4j-api
标记为 <scope>provided</scope>
,因为容器已经为您提供了该依赖项。这应该是您需要做的全部。
我知道现在回答有点晚了,但也许它对某人有帮助。
运行 使用 WildFly 25.0.0 遇到同样的问题。
解决方法: 在文件夹“META-INF”中的 war 存档中创建一个名为“jboss-deployment-structure.xml”的文件,并指定应从类路径中排除哪些模块:
<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>
我写在这里: https://gist.github.com/BlueSKySec/63006f7cd6bef717af0bae71c1e3a9dc