<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="3 seconds">

	<property name="application" value="book" />
	<property name="pattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS}[TraceId:%X{X-B3-TraceId:-} SpanId:%X{X-B3-SpanId:-} ParentSpanId:%X{X-B3-ParentSpanId:-}] [%thread] %-5level %logger{50}:%L - %msg%n" />

	<!-- 控制台调试输出 -->
	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<!--格式化输出：%d表示日期，%thread表示线程名，%-5level：级别从左显示5个字符宽度%msg：日志消息，%n是换行符 -->
			<pattern>${pattern}</pattern>
		</encoder>
		<!--日志级别过滤-->
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>DEBUG</level>
		</filter>
	</appender>

	<!-- INFO级别日志 -->
	<appender name="info_apd" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<!--日志文件输出的文件名 -->
			<FileNamePattern>logs/info/${application}-info-%d{yyyy-MM-dd}.%i.log</FileNamePattern>
			<!--日志文件保留天数 -->
			<MaxHistory>10</MaxHistory>
			<!--日志文件最大的大小 -->
			<timeBasedFileNamingAndTriggeringPolicy
					class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<!-- or whenever the file size reaches 50MB -->
				<maxFileSize>70MB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>

		</rollingPolicy>
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<pattern>${pattern}</pattern>
		</encoder>
		<!--日志级别过滤-->
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>INFO</level>
		</filter>

	</appender>

	<!-- WARN级别日志 -->
	<appender name="warn_apd" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<!--日志文件输出的文件名 -->
			<FileNamePattern>logs/warn/${application}-warn-%d{yyyy-MM-dd}.%i.log</FileNamePattern>
			<!--日志文件保留天数 -->
			<MaxHistory>20</MaxHistory>
			<!--日志文件最大的大小 -->
			<timeBasedFileNamingAndTriggeringPolicy
					class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<!-- or whenever the file size reaches 50MB -->
				<maxFileSize>20MB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>

		</rollingPolicy>
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<pattern>${pattern}</pattern>
		</encoder>
		<!--日志级别过滤-->
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>WARN</level>
		</filter>

	</appender>

	<!-- ERROR级别日志 -->
	<appender name="error_apd" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<!--日志文件输出的文件名 -->
			<FileNamePattern>logs/error/${application}-error-%d{yyyy-MM-dd}.%i.log</FileNamePattern>
			<!--日志文件保留天数 -->
			<MaxHistory>30</MaxHistory>
			<!--日志文件最大的大小 -->
			<timeBasedFileNamingAndTriggeringPolicy
					class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<!-- or whenever the file size reaches 50MB -->
				<maxFileSize>20MB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>

		</rollingPolicy>
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<pattern>${pattern}</pattern>
		</encoder>
		<!--日志级别过滤-->
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>ERROR</level>
		</filter>
	</appender>

	<!-- 监控日志 -->
	<appender name="monitorLogFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<!--日志文件输出的文件名 -->
			<FileNamePattern>logs/monitor/${application}-monitor-%d{yyyy-MM-dd_HH}.%i.log</FileNamePattern>
			<!--日志文件保留天数 -->
			<MaxHistory>10</MaxHistory>
			<!--日志文件最大的大小 -->
			<timeBasedFileNamingAndTriggeringPolicy
					class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<!-- or whenever the file size reaches 50MB -->
				<maxFileSize>3GB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>

		</rollingPolicy>
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<pattern>%msg%n</pattern>
		</encoder>
		<!--日志级别过滤-->
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>INFO</level>
		</filter>
	</appender>
	<appender name="asyncMonitorLogAppender" class="ch.qos.logback.classic.AsyncAppender">
		<appender-ref ref="monitorLogFileAppender" />
	</appender>
	<logger name="com.pcloud.universe.monitorlog.MonitorUtilImpl" level="INFO" additivity="false">
		<appender-ref ref="asyncMonitorLogAppender" />
	</logger>

	<!-- INFO级别以上的日志全部都输出，不同的级别输出在不同的文件里面 -->
	<root>
		<level value="INFO"/>
		<appender-ref ref="STDOUT" />
		<appender-ref ref="info_apd" />
		<appender-ref ref="warn_apd" />
		<appender-ref ref="error_apd" />
	</root>

	<logger name="net.sf.ehcache" level="INFO"/>
	<logger name="druid.sql" level="INFO"/>
	<logger name="org.springframework.cloud.openfeign.FeignClientFactoryBean" level="ERROR"/>
	<logger name="com.netflix.discovery.shared.resolver.aws.ConfigClusterResolver" level="WARN"/>
	<logger name="org.apache.ibatis.io.ResolverUtil" level="ERROR"/>

</configuration>