Application specific logging in WildFly 9.0.1 FINAL (SL4J + Logback)

可紊 提交于 2019-12-12 02:49:56

问题


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:

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>

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>

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>

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

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?


回答1:


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>


来源:https://stackoverflow.com/questions/32337285/application-specific-logging-in-wildfly-9-0-1-final-sl4j-logback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!