<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="false" scanPeriod="60 seconds" debug="false">
	<include resource="org/springframework/boot/logging/logback/defaults.xml"/>

	<!-- 基于 converter -->
	<conversionRule conversionWord="sensitive"
					converterClass="com.github.houbb.sensitive.logback.converter.SensitiveLogbackConverter"/>

	<!--定义配置文件关联属性 1.打印级别 2.当前运行环境 3.当前应用名称-->
	<springProperty scope="context" name="app.name"
					source="spring.application.name"/>
	<springProperty scope="context" name="logging.level"
					source="logging.level.global"/>
	<springProperty scope="context" name="environment"
					source="spring.profiles.active"/>

	<property name="APP_NAME" value="${app.name}"/>
	<property name="LOG_PATH" value="${user.home}/${APP_NAME}/logs"/>
	<property name="LOG_FILE" value="${LOG_PATH}/application.log"/>
	<property name="FILE_LOG_PATTERN"
			  value="%d %-5level [%thread %logger - %sensitive%n"/>
	<property name="CONSOLE_LOG_PATTERN"
			  value="%d{yyyy-MM-dd HH:mm:ss} | %boldRed(serverName:${APP_NAME}) | %highlight([%thread] %-5level) | %boldYellow(logName:%logger{16})  | %boldGreen(%tid)  | Msg:%msg%n"/>
	<property name="FILE_LOG_PATTERN"
			  value="%d{yyyy-MM-dd HH:mm:ss} - serverName:${APP_NAME} - [%thread] %-5level logName:%logger - %tid - Msg:%msg%n"/>

	<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
		</filter>
		<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
			<layout
				class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
				<pattern>${CONSOLE_LOG_PATTERN}</pattern>
			</layout>
		</encoder>
	</appender>

	<appender name="fileError"
			  class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>${LOG_PATH}/${APP_NAME}-error.log</file>
		<rollingPolicy
			class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
			<fileNamePattern>
				${LOG_PATH}/bak/%d{yyyy-MM}/${APP_NAME}-info-error-%d{yyyy-MM-dd}.%i.log.gz
			</fileNamePattern>
			<maxHistory>10</maxHistory>
			<maxFileSize>10MB</maxFileSize>
			<totalSizeCap>1GB</totalSizeCap>
		</rollingPolicy>
		<append>true</append>
		<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
			<layout
				class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
				<pattern>${FILE_LOG_PATTERN}</pattern>
			</layout>
			<charset>UTF-8</charset>
		</encoder>
		<filter class="ch.qos.logback.classic.filter.LevelFilter">
			<level>ERROR</level>
			<onMatch>ACCEPT</onMatch>
			<onMismatch>DENY</onMismatch>
		</filter>
	</appender>

	<appender name="fileInfo"
			  class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>${LOG_PATH}/${APP_NAME}-info.log</file>
		<rollingPolicy
			class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
			<fileNamePattern>
				${LOG_PATH}/bak/%d{yyyy-MM}/${APP_NAME}-info-%d{yyyy-MM-dd}.%i.log.gz
			</fileNamePattern>
			<maxHistory>10</maxHistory>
			<maxFileSize>10MB</maxFileSize>
			<totalSizeCap>1GB</totalSizeCap>
		</rollingPolicy>
		<append>true</append>
		<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
			<layout
				class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
				<pattern>${FILE_LOG_PATTERN}</pattern>
			</layout>
			<charset>UTF-8</charset>
		</encoder>
		<filter class="ch.qos.logback.classic.filter.LevelFilter">
			<level>INFO</level>
			<onMatch>ACCEPT</onMatch>
			<onMismatch>DENY</onMismatch>
		</filter>
	</appender>


	<springProfile name="${environment}">
		<root level="${logging.level}">
			<appender-ref ref="console"/>
			<appender-ref ref="fileInfo"/>
			<appender-ref ref="fileError"/>
		</root>
	</springProfile>
</configuration>
