【问题标题】:SLF4J logging with jboss/wildfly 10使用 jboss/wildfly 10 进行 SLF4J 日志记录
【发布时间】:2016-12-05 22:00:07
【问题描述】:

我有一个在 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”中的所有内容?
  • 我在 Eclipse 中将 Wildfly 服务器作为插件运行。通过使用控制台处理程序,我希望将日志写入 Eclipse 的控制台

目前,它不起作用,我不确定我配置错误的 3 个步骤中的哪一个。这是来自standalone.xml 的sn-p:

 ...            
        <logger category="com.company">
            <level name="DEBUG"/>
        </logger>
        <root-logger>
            <level name="DEBUG"/>
            <handlers>
                <handler name="CONSOLE"/>
                <handler name="FILE"/>
            </handlers>
        </root-logger>
 ...

【问题讨论】:

    标签: java eclipse logging wildfly slf4j


    【解决方案1】:

    standalone.xml 中的内容是正确的。但是,您包含了太多 slf4j 依赖项。 slf4j 首先是一个日志外观。无需在您的应用程序中包含实现依赖项。

    首先,您需要从 pom.xml 中删除 log4j2 依赖项。然后将org.slf4j:slf4j-api 标记为&lt;scope&gt;provided&lt;/scope&gt;,因为容器已经为您提供了该依赖项。这应该就是你需要做的。

    【讨论】:

    • 值得注意的是,您需要弄清楚 WildFly 使用的 SLF4J 版本。对于 WildFly 10,它是 1.7.7,您可以在 modules/system/layers/base/org/slf4j/main/ 中找到 JAR。
    • 我认为这无关紧要。 slf4j API 应该与旧的和新的 1.7.x 版本的 API 兼容。
    【解决方案2】:

    我知道答案有点晚了,但也许它可以帮助某人。

    使用 WildFly 25.0.0 时遇到了同样的问题。

    解决方案: 在名为“jboss-deployment-structure.xml”的文件夹“META-INF”中创建一个名为“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

    【讨论】:

      猜你喜欢
      • 2011-11-07
      • 2013-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多