WildFly 9.0.1 FINAL(SL4J + Logback)中的特定于应用程序的日志记录 [英] Application specific logging in WildFly 9.0.1 FINAL (SL4J + Logback)

查看:156
本文介绍了WildFly 9.0.1 FINAL(SL4J + Logback)中的特定于应用程序的日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我关注了一些文章,并通过遵循一些类似的SO问题来尝试提供解决方案,但仍然无法使它工作-我在任何搜索它的地方都没有创建我的日志文件.

I followed some articles and tried to come with the solution by following some similar SO questions but still can't make this work - my logfile is not being created anywhere I searched for it.

我的目标是在应用程序中捆绑有效的日志记录,而不使用供应商特定的日志记录.我目前的情况如下:

My goal is to have working logging bundled within the application, not use vendor specific logging. My current situation is following:

我已经在MyEAR/META-INF目录中创建了jboss-deployment-structure.xml,其内容如下:

I have created jboss-deployment-structure.xml inside MyEAR/META-INF directory with following content:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <!-- it only affects single deployment -->
        <exclude-subsystems>
            <subsystem name="logging" />
        </exclude-subsystems>
    </deployment>
</jboss-deployment-structure>

然后我也在MyEAR/META-INF目录中并使用以下配置创建了logback.xml:

Then I have created logback.xml also in MyEAR/META-INF directory and with following configuration:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="TMP_FILE" class="ch.qos.logback.core.FileAppender">
        <file>app.log</file>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
    </encoder>
</appender>

<root level="TRACE">
    <appender-ref ref="TMP_FILE" />
</root>

我的依赖项在父POM文件中指定,如下所示:

My dependencies are specified in parent POM file and look like this:

<dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.12</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.3</version>
    </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.1.3</version>
        </dependency>
    </dependencies>

这将导致MyEAR/lib文件夹中保存了这三个JAR文件.

This results in folder MyEAR/lib which then holds those three JAR files.

我想将此日志记录配置保持在EAR级别,以便所有EJB和WAR模块都可以使用它.

I'd like to keep this logging configuration at the EAR level, so all EJB and WAR modules can use it.

要使它正常工作,我需要缺少什么吗?

Is there anything I'm missing to make it work?

推荐答案

您还需要为每个子部署都排除日志子系统.像这样:

You'll need to exclude the logging subsystem for each subdeployment as well. Something like:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <!-- it only affects single deployment -->
        <exclude-subsystems>
            <subsystem name="logging" />
        </exclude-subsystems>
    </deployment>
    <sub-deployment name="mywar.war">
        <exclude-subsystems>
            <subsystem name="logging" />
        </exclude-subsystems>
    </sub-deployment>
    <sub-deployment name="myejb.jar">
        <exclude-subsystems>
            <subsystem name="logging" />
        </exclude-subsystems>
    </sub-deployment>
</jboss-deployment-structure>

这篇关于WildFly 9.0.1 FINAL(SL4J + Logback)中的特定于应用程序的日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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