<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!-- Spring Boot 기본 설정 포함 -->
    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
    
    <!-- 로그 경로 설정 -->
    <property name="LOG_PATH" value="${LOG_PATH:-logs}"/>
    
    <!-- 콘솔 Appender -->
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    
    <!-- 일반 애플리케이션 로그 파일 Appender -->
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}/vessel-batch.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/vessel-batch.log.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
            <maxFileSize>100MB</maxFileSize>
            <maxHistory>30</maxHistory>
            <totalSizeCap>10GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    
    <!-- API 사용 로그 전용 Appender -->
    <appender name="API_USAGE_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}/api-usage.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/api-usage.log.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
            <maxFileSize>500MB</maxFileSize>
            <maxHistory>90</maxHistory>
            <totalSizeCap>50GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} - %msg%n</pattern>
        </encoder>
    </appender>
    
    <!-- WebSocket 사용 로그 전용 Appender -->
    <appender name="WEBSOCKET_USAGE_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH}/websocket-usage.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/websocket-usage.log.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
            <maxFileSize>200MB</maxFileSize>
            <maxHistory>90</maxHistory>
            <totalSizeCap>20GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} - %msg%n</pattern>
        </encoder>
    </appender>
    
    <!-- API_USAGE 로거 (별도 파일에만 기록, 다른 로거로 전파 안함) -->
    <logger name="API_USAGE" level="INFO" additivity="false">
        <appender-ref ref="API_USAGE_FILE"/>
    </logger>
    
    <!-- WEBSOCKET_USAGE 로거 (별도 파일에만 기록, 다른 로거로 전파 안함) -->
    <logger name="WEBSOCKET_USAGE" level="INFO" additivity="false">
        <appender-ref ref="WEBSOCKET_USAGE_FILE"/>
    </logger>
    
    <!-- Root 로거 -->
    <root level="INFO">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
    </root>
    
    <!-- 애플리케이션별 로거 설정 -->
    <logger name="gc.mda.signal_batch" level="INFO"/>
    <logger name="gc.mda.signal_batch.util" level="WARN"/>
    <logger name="org.springframework.batch" level="INFO"/>
    <logger name="org.springframework.jdbc" level="WARN"/>
    <logger name="org.postgresql" level="WARN"/>
    
</configuration>