logback-spring.xml

송지윤·2026년 1월 15일

Spring Boot

목록 보기
72/73

src/main/resources

<configuration scan="true" scanPeriod="60 seconds">

    <!-- YML에서 가져온 변수 -->
	<springProperty scope="context" name="logPath" source="logging.file.path"/>
	<springProperty scope="context" name="fileName" source="logging.file.name"/>
    <property name="maxHistory" value="30" />
    <property name="maxFileSize" value="10MB" />

    <!-- 콘솔 로그 -->
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n</pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>

    <!-- 파일 로그 (날짜 + 용량 기반 롤링) -->
    <appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${logPath}/${fileName}.log</file>

        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!-- 날짜 + 인덱스(%i) + 용량 기반 -->
            <fileNamePattern>${logPath}/${fileName}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            
            <maxFileSize>${maxFileSize}</maxFileSize>
            <maxHistory>${maxHistory}</maxHistory>
        </rollingPolicy>

        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n</pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>

    <!-- 기본 로그 레벨 -->
    <root level="INFO">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="ROLLING" />
    </root>

</configuration>

application.yml

logging:
  level:
    root: DEBUG
    org.springframework.boot.autoconfigure: ERROR
  file:
    path: ./logs
    fileName: paySubAgree

0개의 댓글