SpringBoot Logback配置文件引入子配置文件

主项目Logback

logback-spring-dev.xml

<configuration>
	<include resource="org/springframework/boot/logging/logback/defaults.xml" />
	<include resource="logback-child-log.xml" />

	<springProperty scope="context" name="SYSLOG_FILE" source="logging.file" defaultValue="/opt/app.log" />
	<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
		
		<encoder>
			<pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} @project.name@ ${MY_POD_NAME} %thread %logger{36} %-5level %msg%npattern>
		encoder>
	appender>
	
	<root level="${logging.level.root}">
		<appender-ref ref="console" />
	root>
configuration>

子项目Logback

logback-child-log.xml


<included>
    
    <appender name="logicFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>/opt/logic_app.logfile>

        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>/opt/logs/@project.name@/logic_app.${MY_POD_NAME}.%d{yyyy-MM-dd}.logfileNamePattern>
            
            <maxHistory>14maxHistory>
        rollingPolicy>

        <encoder>
            <pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} @project.name@ ${MY_POD_NAME} %thread %logger{36} %-5level %msg%npattern>
            <charset>UTF-8charset>
        encoder>
    appender>

    <logger name="com.common.LogPrint" additivity="false" level="INFO">
        <appender-ref ref="logicFile"/>
    logger>

included>

根据子项目中Logback的配置,通过LogPrint类打印的日志,都会打印到指定的文件中,不会打印到主项目的日志文件。

核心需要注意的是,子项目的Logback.xml中的配置,需要使用 标签才可以被主项目引入成功。

你可能感兴趣的:(Java,Web,spring,boot,logback,java)