Logback overrides logback.xml dependencies
I am developing an application using another project as maven dependency.
Expectation
I want my dependency to use its own logback.xml to log into its own file. And I want the application to use its own logback.xml file to log into the console and a separate file apart from the dependency. And I want both files to be in the journal folder next to the application bank.
What he is doing now
But for now, both the application and the dependency use the logback.xml application and everything is logged in the console and in the same file.
How can I solve this problem?
Project details
Both use logback as a logger. A dependency is a protocol implementation that logs communication information in a file, which must be in a separate file than application logs. Both the application and the dependency have the classic maven structure with a logback.xml file inside the resources folder.
Logback.xml Dependency
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{HH:mm:ss}|%msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>./log/communications.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<root level="DEBUG">
<appender-ref ref="FILE"/>
</root>
</configuration>
Logback.xml application
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<appender name="FILEAPPLI" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{HH:mm:ss}|%msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>./log/debugfileappli.%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<root level="DEBUG">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILEAPPLI"/>
</root>
</configuration>
source to share
I found a solution. In my dependency code, I am calling a specific logger name.
private static final Logger logger = LoggerFactory.getLogger("dependencyLogger");
And I declare this logger in my logback.xml application
<logger name="dependencyLogger" level="debug">
<additivity="false">
<appender-ref ref="FILE-AUDIT" />
<appender-ref ref="STDOUT" />
</logger>
This way I can handle as I want the entire log to depend on one logback.xml
source to share