Spring Boot下生产环境logback日志配置

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
	<contextName>vhsc-api4</contextName>
	<!-- 控制台输出 -->
	<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
		<encoder>
			<pattern>%d %-5level %logger{36}[%line] - %msg%n</pattern>
		</encoder>
	</appender>

	<!-- 输出到文件 -->
	<appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<filter class="ch.qos.logback.classic.filter.LevelFilter">
			<level>DEBUG</level>
			<onMatch>ACCEPT</onMatch>
			<onMismatch>DENY</onMismatch>
		</filter>
		<file>${LOG_PATH}/debug.log</file>
		<!-- 设置滚动策略 -->
		<!-- 按天来回滚,如果需要按小时来回滚,则设置为{yyyy-MM-dd_HH} -->
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<!--设置日志命名模式 -->
			<fileNamePattern>${LOG_PATH}/debug.log.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
			<!-- 如果按天来回滚,则最大保存时间为60天,60天之前的都将被清理掉 这里的值与滚动策略模式有关 -->
			<maxHistory>60</maxHistory>
			<!-- 按照日期进行归档,并且对日志文件大小进行限制 -->
			<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<!-- 设置文件大于1KB进行压缩归档 -->
				<maxFileSize>2KB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>
		</rollingPolicy>
		<encoder><!-- 格式化输出 -->
			<pattern>%d %-5level %logger{36}[%line] - %msg%n</pattern>
		</encoder>
	</appender>

	<!-- 输出到文件 -->
	<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<filter class="ch.qos.logback.classic.filter.LevelFilter">
			<level>INFO</level>
			<onMatch>ACCEPT</onMatch>
			<onMismatch>DENY</onMismatch>
		</filter>
		<file>${LOG_PATH}/info.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<fileNamePattern>${LOG_PATH}/info.log.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
			<maxHistory>60</maxHistory>
			<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<maxFileSize>2KB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>
		</rollingPolicy>
		<encoder>
			<pattern>%d %-5level %logger{36}[%line] - %msg%n</pattern>
		</encoder>
	</appender>
	<appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<filter class="ch.qos.logback.classic.filter.LevelFilter">
			<level>WARN</level>
			<onMatch>ACCEPT</onMatch>
			<onMismatch>DENY</onMismatch>
		</filter>
		<file>${LOG_PATH}/warn.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<fileNamePattern>${LOG_PATH}/warn.log.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
			<maxHistory>60</maxHistory>
			<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<maxFileSize>2KB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>
		</rollingPolicy>
		<encoder>
			<pattern>%d %-5level %logger{36}[%line] - %msg%n</pattern>
		</encoder>
	</appender>
	<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<filter class="ch.qos.logback.classic.filter.LevelFilter">
			<level>ERROR</level>
			<onMatch>ACCEPT</onMatch>
			<onMismatch>DENY</onMismatch>
		</filter>
		<file>${LOG_PATH}/error.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<fileNamePattern>${LOG_PATH}/error.log.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
			<maxHistory>60</maxHistory>
			<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<maxFileSize>2KB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>
		</rollingPolicy>
		<encoder>
			<pattern>%d %-5level %logger{36}[%line] - %msg%n</pattern>
		</encoder>
	</appender>

	<root level="info">
		<appender-ref ref="CONSOLE" />
		<appender-ref ref="INFO_FILE" />
		<appender-ref ref="WARN_FILE" />
		<appender-ref ref="ERROR_FILE" />
	</root>

	<springProfile name="test,dev">
		<logger name="com.viewhigh.vhsc.hospital" level="debug" additivity="false">
			<appender-ref ref="CONSOLE" />
			<appender-ref ref="DEBUG_FILE" />
			<appender-ref ref="INFO_FILE" />
			<appender-ref ref="WARN_FILE" />
			<appender-ref ref="ERROR_FILE" />
		</logger>
	</springProfile>
	<springProfile name="prod">
		<logger name="com.viewhigh.vhsc.hospital" level="info" additivity="false">
			<appender-ref ref="CONSOLE" />
			<appender-ref ref="INFO_FILE" />
			<appender-ref ref="WARN_FILE" />
			<appender-ref ref="ERROR_FILE" />
		</logger>
	</springProfile>
</configuration>