Spring boot 如何在log-back.xml中包含xml
我正在为日志编写一个定制的SpringBootStarter项目。我的logback-spring.xml变大了,希望将appender放在单独的文件(console-appender.xml和file appender.xml)中,并希望包含在logback-spring.xml文件中,如下所示。我将所有这三个XML放在我的定制初学者项目的src/main/resources文件夹中Spring boot 如何在log-back.xml中包含xml,spring-boot,logback,spring-logback,Spring Boot,Logback,Spring Logback,我正在为日志编写一个定制的SpringBootStarter项目。我的logback-spring.xml变大了,希望将appender放在单独的文件(console-appender.xml和file appender.xml)中,并希望包含在logback-spring.xml文件中,如下所示。我将所有这三个XML放在我的定制初学者项目的src/main/resources文件夹中 <?xml version="1.0" encoding="UTF-8"?> <config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProperty scope="context" name="JSONLOGSENABLED" source="spring.logs.json.enabled" defaultValue="true" />
<springProperty scope="context" name="JSONLOGSAPPENDER" source="spring.logs.json.appender" defaultValue="console" />
<if condition='property("JSONLOGSENABLED").equalsIgnoreCase("true")'>
<then>
<include file="{path to file}/console-appender.xml"/>
<include file="{path to file}/file-appender.xml"/>
<root level="INFO">
<if condition='property("JSONLOGSAPPENDER").equalsIgnoreCase("file")'>
<then>
<appender-ref ref="FILEJSON" />
</then>
<else>
<appender-ref ref="CONSOLEJSON" />
</else>
</if>
</root>
</then>
</if>
<logger
name="org.springframework.web.filter.CommonsRequestLoggingFilter">
<level value="DEBUG" />
</logger>
</configuration>
file-appender.xml
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>testFile.log</file>
<append>true</append>
<!-- set immediateFlush to false for much higher logging throughput -->
<immediateFlush>true</immediateFlush>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
testFile.log
真的
真的
%-4相对[%thread]-5级别%logger{35}-%msg%n
但是,当在我的spring引导应用程序中使用此启动器时,它无法解析控制台和文件appender文件
我尝试了以下路径:
<include file="/src/main/resources/console-appender.xml"/>
<include file="./console-appender.xml"/>
<include resource="console-appender.xml"/>
在这种情况下如何正确包含文件?是的,这是可能的。Logback使用Joran,因此您必须遵守Joran规则。
有关更多信息,请参阅 无论如何,这是做你想要做的事情的首选方式。
例如,我定义了两个文件,然后您可以根据自己的喜好进行调整 logbackspring.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="console-appender.xml"/>
<root level="debug">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
控制台appender.xml
<included>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{"yyyy-MM-dd HH:mm:ss.SSS", Europe/Rome} [%mdc{id}] [%-11thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
</included>
%日期{“yyyy-MM-dd HH:MM:ss.SSS”,欧洲/罗马}[%mdc{id}][%-11thread]-5级别%logger{36}-%msg%n
请注意,
标签是必需的完美!!完全错过标签。。。谢谢