<?xml version="1.0" encoding="UTF-8"?>

<configuration scan="true" scanPeriod="5 minutes" >
    <springProperty scope="context" name="logstash" source="logging.logstash"/>
    <springProperty scope="context" name="logpath" source="logging.path"/>
    <contextName>apple</contextName>
    <property name="APP_NAME" value="apple" />
    <property name="ENCODER_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS}|${HOSTNAME}|%level|${APP_NAME}|%class|%thread|%method|%line|%msg%n"/>

    <!-- 控制台输出 -->
    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>
                <pattern>${ENCODER_PATTERN}</pattern>
            </pattern>
        </encoder>
    </appender>

    <!-- 按照每天生成日志文件 -->
    <appender name="dailyfile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${logpath}/${APP_NAME}.log</file>
        <encoder>
            <charset>UTF-8</charset>
            <pattern>${ENCODER_PATTERN}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>
                ${logpath}/${APP_NAME}.log.%d{yyyy-MM-dd}
            </fileNamePattern>
            <maxHistory>30</maxHistory>
        </rollingPolicy>
    </appender>

    <appender name="logstash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <destination>${logstash}</destination>
        <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder">
            <customFields>{"appname":"apple"}</customFields>
        </encoder>
        <connectionStrategy>
            <roundRobin>
                <connectionTTL>5 minutes</connectionTTL>
            </roundRobin>
        </connectionStrategy>
    </appender>

    <!-- all,debug,info,warn,error -->
    <root>
        <level value="info" />
        <appender-ref ref="stdout" />
        <appender-ref ref="dailyfile" />
        <appender-ref ref="logstash" />
    </root>

    <logger name="com.liying" level="DEBUG" />
    <logger name="org.springframework.web" level="INFO" />

</configuration>