<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<configuration>
    <include resource="org/springframework/boot/logging/logback/defaults.xml" />
    <property name="CONSOLE_PATTERN" value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS, Asia/Seoul}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) [${java.rmi.server.hostname:-127.0.0.1}] [${nd.hostname:-localhost}] %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr([%class{5} > %method:%line]){magenta} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
    <property name="FILE_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS, Asia/Seoul} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} [%class{5} > %method:%line] : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
    <property name="LOG_FILE" value="${LOG_FILE:-spring}"/>

    <springProperty scope="context" name="LOG_PATH" source="log.path"/>
    <springProperty name="SPRING_APPLICATION_NAME" source="spring.application.name" />

    <appender name="CONSOLE_APPENDER" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>${CONSOLE_PATTERN}</pattern>
            <charset>utf8</charset>
        </encoder>
    </appender>

    <appender name="FILE_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}/${LOG_FILE}.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/old/${LOG_FILE}-%d{yyyyMMdd-HH}.%i.log.gz</fileNamePattern>
            <maxHistory>720</maxHistory>
            <maxFileSize>300MB</maxFileSize>
        </rollingPolicy>
        <encoder>
            <pattern>${FILE_PATTERN}</pattern>
            <charset>utf8</charset>
        </encoder>
    </appender>

    <appender name="FILE_ERROR_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}/${LOG_FILE}-error.log</file>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/old/${LOG_FILE}-error-%d{yyyyMMdd-HH}.%i.log.gz</fileNamePattern>
            <maxHistory>720</maxHistory>
            <maxFileSize>300MB</maxFileSize>
        </rollingPolicy>
        <encoder>
            <pattern>${FILE_PATTERN}</pattern>
            <charset>utf8</charset>
        </encoder>
    </appender>

    <!-- 로그 레벨 설정 -->
    <logger name="java.sql" level="INFO" />
    <logger name="org.apache" level="WARN" />
    <logger name="org.springframework" level="INFO" />
    <logger name="io.swagger.models.parameters.AbstractSerializableParameter" level="ERROR" />

    <!-- spring profiles 에 따른 로그 레벨 설정 (spring boot 에서만 설정 가능함.) -->
    <springProfile name="local">
        <logger name="jdbc" level="OFF"/>
        <logger name="jdbc.sqlonly" level="INFO"/>
        <logger name="jdbc.resultsettable" level="INFO"/>
        <logger name="org.hibernate" level="OFF" />
        <logger name="com.oqpo.api" level="DEBUG" />

        <!-- 정의 되지 않은 logger 들에게 일괄 적용됨 -->
        <root level="INFO">
            <appender-ref ref="CONSOLE_APPENDER" />
            <appender-ref ref="FILE_APPENDER" />
            <appender-ref ref="FILE_ERROR_APPENDER" />
        </root>
    </springProfile>

    <springProfile name="dev">
        <logger name="jdbc" level="OFF"/>
        <logger name="jdbc.sqlonly" level="INFO"/>
        <logger name="jdbc.resultsettable" level="INFO"/>
        <logger name="org.hibernate" level="OFF" />
        <logger name="com.oqpo.api" level="INFO" />

        <!-- 정의 되지 않은 logger 들에게 일괄 적용됨 -->
        <root level="INFO">
            <appender-ref ref="FILE_APPENDER" />
            <appender-ref ref="FILE_ERROR_APPENDER" />
        </root>
    </springProfile>

    <springProfile name="prod">
        <logger name="org.hibernate" level="ERROR" />
        <logger name="com.oqpo.api" level="INFO" />

        <!-- 정의 되지 않은 logger 들에게 일괄 적용됨 -->
        <root level="ERROR">
            <appender-ref ref="FILE_ERROR_APPENDER" />
        </root>
    </springProfile>
</configuration>
