Logback logging maven multi-module

1.2k Views Asked by At

I'm developing an application made of multiple modules that will be deployed on wildfly 13. One of these modules is using another of my project as a jar maven dependency.(included to pom)

Expectation

I want my dependency using its own logback.xml to log in its own file. And I want the application using its own logback.xml file to log in the console and a separate file than the dependency.

What it does now

For the moment both the application module (com.test.app.console.ca.operation)

which include the jar dependency and the dependency use the dependency's logback.xml and everything is logged in the same file. This is very strange to me because of other modules from the main application (which dont have dependecy from the library jar), are correctly logging in the right file.

Could please help me to understand and solve this problem?

Details about the projects

Both use logback as a logger. The dependency is a security implementation that logs communication information in a file that must be in a separate file than application logs. Both the application and the dependency have a classic maven structure with the logback.xml file inside the resource folder.

The main modules logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
    <property resource="application.properties" />
    <appender name="STDOUT"
        class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder 
            by default -->
        <encoder>
            <pattern>%d{ISO8601} [%thread] %-5level %logger - %msg %n</pattern>
        </encoder>
    </appender>
    <!--Application Log (Daily rolling file appender) -->
    <appender name="appCaLog"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${jboss.server.log.dir}/main_modules_app.log</File>
        <rollingPolicy
            class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${jboss.server.log.dir}/main_modules_app.log.%d{yyyy-MM-dd}.log
            </FileNamePattern>
        </rollingPolicy>

        <encoder>
            <pattern>%d{ISO8601} [%thread] %-5level %logger - %msg %n</pattern>
        </encoder>
    </appender>

    <logger name="com.test.app.console.ca.usermanagement"
        level="${cops.usermanagement.log.level}" additivity="false">
        <appender-ref ref="appCaLog" />
    </logger>

    <logger name="com.test.app.console.ca.operation"
        level="${cops.operation.log.level}" additivity="false">
        <appender-ref ref="appCaLog" />
    </logger>

    <logger name="com.test.app.console.ca"
        level="${cops.main.log.level}" additivity="false">
        <appender-ref ref="appCaLog" />
    </logger>

    <root level="INFO">
        <appender-ref ref="appCaLog" />
    </root>
</configuration>

The dependency logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
    <appender name="STDOUT"
        class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder 
            by default -->
        <encoder>
            <pattern>%d{ISO8601} [%thread] %-5level %logger - %msg %n</pattern>
        </encoder>
    </appender>
    <!--Application Log (Daily rolling file appender) -->
    <appender name="dependencyCaCryptoLog"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${jboss.server.log.dir}/dependency_module.log</File>
        <rollingPolicy
            class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${jboss.server.log.dir}/dependency_module.log.%d{yyyy-MM-dd}.log
            </FileNamePattern>
        </rollingPolicy>

        <encoder>
            <pattern>%d{ISO8601} [%thread] %-5level %logger - %msg %n</pattern>
        </encoder>
    </appender>

    <logger name="com.test.app.console.ca.crypto"
        level="INFO" additivity="false">
        <appender-ref ref="dependencyCaCryptoLog" />
    </logger>

    <root level="INFO">
        <appender-ref ref="dependencyCaCryptoLog" />
    </root>
</configuration>
0

There are 0 best solutions below