Reputation: 785
I have jar package with classes which are using Logger.
This jar added into application as dependency.
I have a few logback-test.xml
files. The first file is defined in my application, the second defined in jar. In case class from jar uses logger with name my-custom-logger
it's necessary to follow configuration which is defined in the second file (which is in the jar). However, this config is not used. The application always uses the first config file.
My application is running on Tomcat, so I think the Tomcat is responding for logging.
Could somebody advice how to solve this issue?
The first file:
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{HH:mm:ss.SSS} %highlight(%-5level) [%cyan(%-40.40logger{39})] %msg %gray(%mdc) %red(%rootException) %n</pattern>
</encoder>
</appender>
<!-- root -->
<root level="info">
<appender-ref ref="CONSOLE" />
</root>
The second file(from jar):
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%date{EEE dd HH:mm:ss} [specific prefix] [%thread] %-5level %logger{0} - %msg%n
</Pattern>
</layout>
</appender>
<logger name="my-custom-logger" level="info" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
Upvotes: 0
Views: 637
Reputation: 1530
I suggest you include your second configuration file (the one in the jar) in the first configuration file (the one used by your application) using the include tag.
Bellow an example of the usage of include:
<configuration>
<include resource="logback-second.xml"/> <!-- here I included the configuration file from jar using it's name
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{HH:mm:ss.SSS} %highlight(%-5level) [%cyan(%-40.40logger{39})] %msg %gray(%mdc) %red(%rootException) %n</pattern>
</encoder>
</appender>
<!-- root -->
<root level="info">
<appender-ref ref="CONSOLE" />
</root>
Upvotes: 2