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

    <property name="PROJECT_NAME"    value="dsrc-comm-server"/>
    <property name="ROOT_LOG_LEVEL"  value="INFO"/>
    <property name="LOG_CHARSET"     value="UTF-8" />
    <property name="LOG_PATH"        value="${user.dir}/logs/"/>
    <property name="LOG_BACKUP_PATH" value="${user.dir}/logs/backup/"/>

    <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_PACKET"      value="dsrc-packet"/>
    <property name="LOG_FILE_NAME_SESSION"     value="dsrc-session.log"/>
    <property name="LOG_FILE_NAME_CENTER_COMM" value="dsrc-center-comm.log"/>
    <property name="LOG_FILE_NAME_SQL"         value="dsrc-sql.log"/>
    <property name="LOG_FILE_NAME_SCHEDULE"    value="dsrc-schedule.log"/>
    <property name="LOG_FILE_NAME_STATISTICS"  value="dsrc-statistics.log"/>

    <property name="MAX_FILESIZE" value="10MB"/>
    <property name="MAX_HISTORY"  value="30"/>
    <property name="LOG_PATTERN_FILE"        value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] %msg%n"/>
    <property name="LOG_PATTERN_ERROR"       value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%30t] [%5level] %42logger{35}.%-20M ${PID:-} %n%msg%n"/>
    <property name="LOG_PATTERN_PACKET"      value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] %msg%n"/>
    <property name="LOG_PATTERN_SESSION"     value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] %msg%n"/>
    <property name="LOG_PATTERN_CENTER_COMM" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] %msg%n"/>
    <property name="LOG_PATTERN_SQL"         value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] %msg%n"/>
    <property name="LOG_PATTERN_SCHEDULE"    value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] %msg%n"/>
    <property name="LOG_PATTERN_STATISTICS"  value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] %msg%n"/>
    <!--<property name="LOG_PATTERN_CONSOLE"     value="%d{HH:mm:ss.SSS} [%30thread] %highlight([%5level]) %cyan(%42logger{35}.%-20M)${PID:-} : %msg%n"/>
    <property name="LOG_PATTERN_FILE"        value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%30t] [%5level] %42logger{35}.%-20M ${PID:-} : %msg%n"/>
    <property name="LOG_PATTERN_ERROR"       value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%30t] [%5level] %42logger{35}.%-20M ${PID:-} : %msg%n"/>
    <property name="LOG_PATTERN_PACKET"      value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] [%thread] %msg%n"/>
    <property name="LOG_PATTERN_SESSION"     value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] %msg%n"/>
    <property name="LOG_PATTERN_CENTER_COMM" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%30t] [%5level] %42logger{35}.%-20M ${PID:-} : %msg%n"/>
    <property name="LOG_PATTERN_SQL"         value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] [%thread] %msg%n"/>
    <property name="LOG_PATTERN_SCHEDULE"    value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] [%30thread] %msg%n"/>
    <property name="LOG_PATTERN_CONSOLE"     value="[%d{HH:mm:ss.SSS}] %highlight([%5level]) %highlight(${PID:-}): %cyan(%msg) [%class{0}.%method] [%thread] %n"/>
    -->
    <property name="LOG_PATTERN_CONSOLE" value="[%d{HH:mm:ss.SSS}] %highlight([%5level]) %highlight(${PID:-}): %cyan(%msg) %n"/>

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

    <appender name="FILE_PACKET" class="ch.qos.logback.classic.sift.SiftingAppender">
        <discriminator>
            <key>id</key>
            <defaultValue>${LOG_FILE_NAME_PACKET}</defaultValue>
        </discriminator>
        <sift>
            <appender name="FILE-${id}" class="ch.qos.logback.core.rolling.RollingFileAppender">
                <file>${LOG_PATH}packet/${id}.log</file>
                <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
                    <charset>${LOG_CHARSET}</charset>
                    <Pattern>${LOG_PATTERN_PACKET}</Pattern>
                </encoder>

                <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
                    <FileNamePattern>${LOG_BACKUP_PATH}packet/${id}.${LOG_FILE_NAME_PATTERN}</FileNamePattern>
                    <maxFileSize>${MAX_FILESIZE}</maxFileSize>
                    <maxHistory>${MAX_HISTORY}</maxHistory>
                </rollingPolicy>
            </appender>
        </sift>
    </appender>

    <appender name="FILE_LOG" 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="FILE_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>

    <root level="INFO">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE_LOG"/>
        <appender-ref ref="FILE_ERROR"/>
    </root>

    <logger name="com.its.app.xnettcp" level="DEBUG" additivity="false">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE_PACKET"/>
        <appender-ref ref="FILE_ERROR"/>
    </logger>

    <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>

    <logger name="com.its.app.xnetudp" level="DEBUG" additivity="false">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="CENTER_COMM"/>
        <appender-ref ref="FILE_ERROR"/>
    </logger>

    <appender name="FILE_SESSION" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}${LOG_FILE_NAME_SESSION}</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_SESSION}.${LOG_FILE_NAME_PATTERN}</fileNamePattern>
            <maxFileSize>${MAX_FILESIZE}</maxFileSize>
            <maxHistory>${MAX_HISTORY}</maxHistory>
        </rollingPolicy>
    </appender>

    <logger name="com.its.app.xnettcp.handler" level="DEBUG" additivity="true">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE_SESSION"/>
        <appender-ref ref="FILE_ERROR"/>
    </logger>

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

    <logger name="com.its.dsrc.service.StatisticsServices" level="DEBUG" additivity="false">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE_STATISTICS"/>
        <appender-ref ref="FILE_ERROR"/>
    </logger>

    <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}${LOG_FILE_NAME_SCHEDULE}.${LOG_FILE_NAME_PATTERN}</fileNamePattern>
            <maxFileSize>${MAX_FILESIZE}</maxFileSize>
            <maxHistory>${MAX_HISTORY}</maxHistory>
        </rollingPolicy>
    </appender>

    <logger name="com.its.app.scheduler" level="DEBUG" additivity="false">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE_SCHEDULE"/>
        <appender-ref ref="FILE_ERROR"/>
    </logger>

    <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}${LOG_FILE_NAME_SQL}.${LOG_FILE_NAME_PATTERN}</fileNamePattern>
            <maxFileSize>${MAX_FILESIZE}</maxFileSize>
            <maxHistory>${MAX_HISTORY}</maxHistory>
        </rollingPolicy>
    </appender>

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

</configuration>
