<?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" />

	<contextName>sxfoundation-server</contextName>

	<property name="log_home" value="./logs"/>

	<!-- 控制台输出 -->
	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
		<!-- 日志输出的文件的格式 -->
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} | [%magenta(%thread) %green(%5L)] %highlight(%-5level) %cyan(%logger{50}) : %msg %n</pattern>
			<charset>UTF-8</charset>
		</encoder>

	</appender>
	<!-- 按照每天生成日志文件 -->
	<appender name="ROOT-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender" level="INFO">
		<append>true</append>

        <!-- 过滤器，只记录 warn 和 info 级别的日志 -->
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>WARN</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>NEUTRAL</onMismatch>
        </filter>

        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>

	    <file>${log_home}/netflix-default.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
			<FileNamePattern>${log_home}/netflix-default.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
			<!-- kb/mb/gb -->
			<maxFileSize>128MB</maxFileSize>
			<!-- 日志文件保留天数 -->
			<maxHistory>14</maxHistory>
		</rollingPolicy>
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} | [%magenta(%thread) %green(%5L)] %highlight(%-5level) %cyan(%logger{50}) : %msg %n</pattern>
			<charset>UTF-8</charset>
		</encoder>

	</appender>

	<!-- 按照每天生成日志文件 -->
	<appender name="ERROR-APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<append>true</append>

		<!-- 过滤器，只记录 error 级别的日志 -->
		<filter class="ch.qos.logback.classic.filter.LevelFilter">
			<level>ERROR</level>
			<onMatch>ACCEPT</onMatch>
			<onMismatch>DENY</onMismatch>
		</filter>

		<!-- 日志名称 -->
		<file>${log_home}/netflix-error.log</file>
		<!-- 每天生成一个日志文件，保存15天的日志文件 -->
		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
			<!--日志文件输出的文件名:按天回滚 daily -->
			<FileNamePattern>${log_home}/netflix-error.log.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
			<!-- kb/mb/gb -->
			<maxFileSize>128MB</maxFileSize>
			<!-- 日志文件保留天数 -->
			<maxHistory>14</maxHistory>
			<totalSizeCap>10GB</totalSizeCap>
		</rollingPolicy>
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<!--格式化输出：%d表示日期，%thread表示线程名，%-5level：级别从左显示5个字符宽度%msg：日志消息，%n是换行符-->
			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} | [%magenta(%thread) %green(%5L)] %highlight(%-5level) %cyan(%logger{50}) : %msg %n</pattern>
			<!-- 编码 -->
			<charset>UTF-8</charset>
		</encoder>
	</appender>

	<!-- 异步输出 -->
	<appender name="ERROR_ASYNC" class="ch.qos.logback.classic.AsyncAppender">
		<!-- 不丢失日志.默认的. 如果discardingThreshold大于0,队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
		<discardingThreshold>0</discardingThreshold>
		<queueSize>10240</queueSize>
		<appender-ref ref="ERROR-APPENDER" />
	</appender>

    <!-- 异步输出 -->
	<appender name="ROOT_ASYNC" class="ch.qos.logback.classic.AsyncAppender">
		<!-- 不丢失日志.默认的. 如果discardingThreshold大于0,队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
		<discardingThreshold>0</discardingThreshold>
		<queueSize>10240</queueSize>
		<appender-ref ref="ROOT-APPENDER" />
	</appender>

    <logger name="jdbc.audit" level="WARN" />
    <logger name="jdbc.resultset" level="WARN" />
    <logger name="jdbc.sqlonly" level="WARN" />
    <logger name="jdbc.sqltiming" level="INFO" />
    <logger name="jdbc.connection" level="WARN" />

	<root level="INFO">
		<appender-ref ref="STDOUT" />
		<appender-ref ref="ERROR_ASYNC" />
		<appender-ref ref="ROOT_ASYNC" />
	</root>
	
	<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>
</configuration>