我正在使用spring,我使用logback-spring.xml自定义了记录器。 在这里:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<!-- defined in application.yml ... -->
<springProperty scope="context" name="logFilePath" source="erp.log.path"/>
<springProperty scope="context" name="APPNAME" source="spring.application.name"/>
<springProperty scope="context" name="PROFILE" source="spring.cloud.config.profile"/>
<property name="APP_LOG_PATH" value="${logFilePath}/${APPNAME}/${PROFILE}"/>
<appender name="apiRest" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<file>${APP_LOG_PATH}/rest/rest_api.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${APP_LOG_PATH}/rest/rest_api%i.log</fileNamePattern>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
</appender>
<logger name="api.rest" level="debug">
<appender-ref ref="apiRest"/>
</logger>
<!-- others logger, like order, product ... -->
<root level="info">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="logfile"/>
</root>
</configuration>
我想通过不同的功能(如订单,产品)分离到不同的logback配置文件,并将它们包含在logback-spring.xml中,然后我得到了logback-spring.xml文件和log-api-rest.xml文件和log-property.xml文件。
log-api-rest.xml
<?xml version="1.0" encoding="UTF-8"?>
<included>
<include resource="log-property.xml"/>
<appender name="apiRest" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<file>${APP_LOG_PATH}/rest/rest_api.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${APP_LOG_PATH}/rest/rest_api%i.log</fileNamePattern>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
</appender>
<logger name="api.rest" level="debug">
<appender-ref ref="apiRest"/>
</logger>
</included>
log-property.xml
<?xml version="1.0" encoding="UTF-8"?>
<included>
<springProperty scope="system" name="logFilePath" source="erp.log.path"/>
<springProperty scope="system" name="APPNAME" source="spring.application.name"/>
<springProperty scope="system" name="PROFILE" source="spring.cloud.config.profile"/>
<property scope="system" name="APP_LOG_PATH" value="${logFilePath}/${APPNAME}/${PROFILE}"/>
</included>
在logback-spring.xml中,仅包含了log-property.xml和log-api-rest.xml(也许存在其他记录器文件),但是它并不符合我的期望。 我该如何解决。