Is there any way that we can override the logback configurations? I know that we define the logback configurations in file named logback.xml
(usually stored in the path src/main/resources
) and I know that by using <include>
tag we can set an external file to be added to logback.xml
just like below:
<configuration>
<!--<include url="file:///d:/ServerConfig.xml"/>-->
<include file="${outPut}/ServerConfig.xml"/>
<logger name="Server" LEVEL="DEBUG">
<appender-ref ref="FILEOUT" />
</logger>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
<!--<appender-ref ref="FILEOUT" />-->
</root>
</configuration>
But what if I want to override this default configuration? For example set the root logger level to INFO.
Here is the included file:
<included>
<!-- <property file="d:/ServerSysVar.properties"/>-->
<property file="${outPut}/ServerSysVar.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{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILEOUT" class="ch.qos.logback.core.FileAppender">
<file>${Sys_Location}/Serverfile4.log</file>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %class{36}.%M %L CLIENT_PORT:%X{ClientPort}- %msg%n</pattern>
</encoder>
</appender>
<logger name="Service" LEVEL="DEBUG">
<appender-ref ref="FILEOUT" />
</logger>
<root>
<appender-ref ref="STDOUT" />
<!-- <appender-ref ref="FILEOUT" />-->
</root>
</included>