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

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

    <property name="PROJECT_NAME"    value="ptatms"/>
    <property name="ROOT_LOG_LEVEL"  value="INFO"/>
    <property name="LOG_CHARSET"     value="UTF-8" />
    <property name="LOG_ENCODING"    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_SESSION"     value="${PROJECT_NAME}-session.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="MAX_FILESIZE" value="${log.max.file-size}"/>
    <property name="MAX_HISTORY"  value="${log.max.history}"/>

    <property name="LOG_PATTERN_CONSOLE"     value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%-5level] %msg%n"/>
    <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_SESSION"     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"/>

    <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}.${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}${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}${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="egovframework.scheduler" level="INFO" additivity="false">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE_SCHEDULE"/>
        <appender-ref ref="ERROR"/>
    </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>
