<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds">
    <shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>

    <property resource="logback.properties"/>

<!--    <springProfile name="dev">-->
<!--        <property name="LOGS_PATH" value="./logs" />-->
<!--    </springProfile>-->

    <property name="PROJECT_NAME"    value="${log.name}"/>
    <property name="ROOT_LOG_LEVEL"  value="${log.level.root}"/>
    <property name="LOG_CHARSET"     value="${log.charset}" />
    <property name="LOG_ENCODING"    value="${log.encoding}"/>
    <property name="LOG_PATH"        value="${log.path}"/>
    <property name="LOG_BACKUP_PATH" value="${log.backup.path}"/>

    <property name="LOG_FILE_NAME"             value="${PROJECT_NAME}.log"/>
    <property name="LOG_FILE_NAME_ERROR"       value="${PROJECT_NAME}.err.log"/>
    <property name="LOG_FILE_NAME_PATTERN"     value="%d{yyyyMMdd}_%i.log.gz"/>
    <property name="LOG_FILE_NAME_SESSION"     value="${PROJECT_NAME}-session.log"/>
    <property name="LOG_FILE_NAME_CENTER_COMM" value="${PROJECT_NAME}-center-comm.log"/>
    <property name="LOG_FILE_NAME_SQL"         value="${PROJECT_NAME}-sql.log"/>
    <property name="LOG_FILE_NAME_SCHEDULE"    value="${PROJECT_NAME}-schedule.log"/>
    <property name="LOG_FILE_NAME_STATISTICS"  value="${PROJECT_NAME}-statistics.log"/>

    <property name="MAX_FILESIZE" value="${log.max.file-size}"/>
    <property name="MAX_HISTORY"  value="${log.max.history}"/>

    <property name="LOG_PATTERN_CONSOLE"     value="${log.pattern.console}"/>
    <property name="LOG_PATTERN_FILE"        value="${log.pattern.file}"/>
    <property name="LOG_PATTERN_ERROR"       value="${log.pattern.error}"/>
    <property name="LOG_PATTERN_SESSION"     value="${log.pattern.session}"/>
    <property name="LOG_PATTERN_CENTER_COMM" value="${log.pattern.center-comm}"/>
    <property name="LOG_PATTERN_SQL"         value="${log.pattern.sql}"/>
    <property name="LOG_PATTERN_SCHEDULE"    value="${log.pattern.schedule}"/>
    <property name="LOG_PATTERN_STATISTICS"  value="${log.pattern.statistics}"/>

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <withJansi>true</withJansi>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <charset>${LOG_CHARSET}</charset>
            <pattern>${LOG_PATTERN_CONSOLE}</pattern>
        </encoder>
    </appender>

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}${LOG_FILE_NAME}</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <charset>${LOG_CHARSET}</charset>
            <pattern>${LOG_PATTERN_FILE}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_BACKUP_PATH}${LOG_FILE_NAME}.${LOG_FILE_NAME_PATTERN}</fileNamePattern>
            <maxFileSize>${MAX_FILESIZE}</maxFileSize>
            <maxHistory>${MAX_HISTORY}</maxHistory>
        </rollingPolicy>
    </appender>

    <appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>error</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <file>${LOG_PATH}${LOG_FILE_NAME_ERROR}</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <charset>${LOG_CHARSET}</charset>
            <pattern>${LOG_PATTERN_ERROR}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_BACKUP_PATH}${LOG_FILE_NAME_ERROR}.%d{yyyy-MM-dd}_%i.log</fileNamePattern>
            <maxFileSize>${MAX_FILESIZE}</maxFileSize>
            <maxHistory>${MAX_HISTORY}</maxHistory>
        </rollingPolicy>
    </appender>

    <appender name="CENTER_COMM" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}${LOG_FILE_NAME_CENTER_COMM}</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <charset>${LOG_CHARSET}</charset>
            <pattern>${LOG_PATTERN_CENTER_COMM}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_BACKUP_PATH}CenterComm/${LOG_FILE_NAME_CENTER_COMM}.${LOG_FILE_NAME_PATTERN}</fileNamePattern>
            <maxFileSize>${MAX_FILESIZE}</maxFileSize>
            <maxHistory>${MAX_HISTORY}</maxHistory>
        </rollingPolicy>
    </appender>

    <appender name="FILE_SQL" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}${LOG_FILE_NAME_SQL}</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <charset>${LOG_CHARSET}</charset>
            <pattern>${LOG_PATTERN_SQL}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_BACKUP_PATH}SQL/${LOG_FILE_NAME_SQL}.${LOG_FILE_NAME_PATTERN}</fileNamePattern>
            <maxFileSize>${MAX_FILESIZE}</maxFileSize>
            <maxHistory>${MAX_HISTORY}</maxHistory>
        </rollingPolicy>
    </appender>

    <appender name="FILE_SCHEDULE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}${LOG_FILE_NAME_SCHEDULE}</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <charset>${LOG_CHARSET}</charset>
            <pattern>${LOG_PATTERN_SCHEDULE}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_BACKUP_PATH}Schedule/${LOG_FILE_NAME_SCHEDULE}.${LOG_FILE_NAME_PATTERN}</fileNamePattern>
            <maxFileSize>${MAX_FILESIZE}</maxFileSize>
            <maxHistory>${MAX_HISTORY}</maxHistory>
        </rollingPolicy>
    </appender>

    <root level="${ROOT_LOG_LEVEL}">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
        <appender-ref ref="ERROR"/>
    </root>

    <logger name="com.its.op.scheduler" level="INFO" additivity="false">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE_SCHEDULE"/>
        <appender-ref ref="ERROR"/>
    </logger>

    <logger name="com.its.op.xnetwork.udp" level="INFO" additivity="false">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
        <appender-ref ref="CENTER_COMM"/>
    </logger>

    <!--
        <logger name="org.apache.ibatis" level="DEBUG" additivity="false">
            <appender-ref ref="CONSOLE"/>
            <appender-ref ref="FILE"/>
            <appender-ref ref="ERROR"/>
        </logger>
    -->

    <logger name="jdbc"                level="OFF"   additivity="false"> <appender-ref ref="FILE_SQL" /> <appender-ref ref="ERROR"/> </logger>
    <logger name="jdbc.sqlonly"        level="DEBUG"  additivity="false"> <appender-ref ref="FILE_SQL" /> <appender-ref ref="ERROR"/>  <appender-ref ref="CONSOLE"/> </logger>
    <logger name="jdbc.sqltiming"      level="DEBUG" additivity="false"> <appender-ref ref="FILE_SQL" /> <appender-ref ref="ERROR"/> </logger>
    <logger name="jdbc.audit"          level="OFF"   additivity="false"> <appender-ref ref="FILE_SQL" /> <appender-ref ref="ERROR"/> </logger>
    <logger name="jdbc.resultset"      level="OFF"  additivity="false"> <appender-ref ref="FILE_SQL" /> <appender-ref ref="ERROR"/> </logger>
    <logger name="jdbc.resultsettable" level="OFF"  additivity="false"> <appender-ref ref="FILE_SQL" /> <appender-ref ref="ERROR"/> </logger>
    <logger name="jdbc.connection"     level="OFF"  additivity="false"> <appender-ref ref="FILE_SQL" /> <appender-ref ref="ERROR"/> </logger>

</configuration>
