<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
	<logger name="org.springframework" level="info"/>
	<property name="log.base" value="../logs" />
	<!-- 控制台输出 -->
	<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
		<!-- encoder默认配置为PartternLayoutEncoder -->
		<Encoding>UTF-8</Encoding>
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{80} -%msg%n</pattern>
			<charset>UTF-8</charset>
		</encoder>
		<target>System.out</target>
	</appender>
	<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
		<destination>10.91.253.209:4563</destination>
		<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder">
			<customFields>
				{"app_name":"DUP","app_type":"app","platform":"DUP","env":"dev"}
			</customFields>
			<timeZone>Asia/Shanghai</timeZone>
			<writeVersionAsInteger>true</writeVersionAsInteger>
			<shortenedLoggerNameLength>36</shortenedLoggerNameLength>
			<charset>UTF-8</charset>
		</encoder>
	</appender>

	<!-- 日志文件输出 -->
	<appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<Encoding>UTF-8</Encoding>
		<File> ${log.base}/dup_debug.log</File><!-- 设置日志不超过${log.max.size}时的保存路径，注意如果 是web项目会保存到Tomcat的bin目录 下 -->
		<!-- 滚动记录文件，先将日志记录到指定文件，当符合某个条件时，将日志记录到其他文件。-->
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<fileNamePattern>${log.base}/logs/dup_debug_all.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
			<maxHistory>30</maxHistory>  <!-- 保存30天 -->
			<totalSizeCap>10GB</totalSizeCap>  <!-- 总日志大小 -->
			<!-- 当天的日志大小 超过${log.max.size}时,压缩日志并保存 -->
			<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<maxFileSize>100MB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>
		</rollingPolicy>
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{80} -%msg%n</pattern>
			<charset>UTF-8</charset>
		</encoder>
	</appender>

    <!-- 日志文件输出 -->
    <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<Encoding>UTF-8</Encoding>
        <File> ${log.base}/dup_error.log</File><!-- 设置日志不超过${log.max.size}时的保存路径，注意如果 是web项目会保存到Tomcat的bin目录 下 -->
        <!-- 滚动记录文件，先将日志记录到指定文件，当符合某个条件时，将日志记录到其他文件。-->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.base}/logs/dup_error_all.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
            <maxHistory>30</maxHistory>  <!-- 保存30天 -->
            <totalSizeCap>10GB</totalSizeCap>  <!-- 总日志大小 -->
            <!-- 当天的日志大小 超过${log.max.size}时,压缩日志并保存 -->
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>100MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
		<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{80} -%msg%n</pattern>
			<charset>UTF-8</charset>
		</encoder>
    </appender>


	<logger name="com.ibatis" level="DEBUG" >
		<appender-ref ref="CONSOLE" />
		<appender-ref ref="LOGSTASH" />
		<appender-ref ref="DEBUG_FILE" />
	</logger>
	<!-- （改）过滤器，可以指定哪些包，哪个记录到等级， -->
	<!-- 运用的场景比如，你只需要com.demo.controller包下的error日志输出。定义好name="com.demo.controller" level="ERROR" 就行了 -->
	<logger name="cn.com.countrygarden.bi.main" level="DEBUG">
		<appender-ref ref="CONSOLE" />
		<appender-ref ref="LOGSTASH" />
		<appender-ref ref="DEBUG_FILE" />
	</logger>

    <logger name="cn.com.countrygarden.bi.main" level="ERROR">
		<appender-ref ref="CONSOLE" />
        <appender-ref ref="ERROR_FILE" />
    </logger>

	<!-- 全局，控制台遇到INFO及以上级别就进行输出 -->
	<root level="DEBUG">
		<appender-ref ref="CONSOLE" />
		<appender-ref ref="LOGSTASH" />
		<appender-ref ref="DEBUG_FILE" />
	</root>
</configuration>