์Šคํ”„๋ง ๋ถ€ํŠธ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ๋Š” ๊ธฐ๋ณธ์ ์ธ ๋กœ๊น… ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ์จ ๋กœ๊ทธ๋ฐฑ์ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์Šคํ”„๋ง ๋ถ€ํŠธ์˜ ํฌํ•จ๋œ org/springframework/boot/logging/logback/base.xml ํŒŒ์ผ์„ ํ† ๋Œ€๋กœ ์ฝ˜์†” ๋ฐ ํŒŒ์ผ๋กœ ๋กœ๊ทธ๋ฅผ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๊ฒŒ ๊ธฐ๋ณธ๊ฐ’์ด ์ •์˜๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. LoggingApplicationListener์— ์˜ํ•ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹คํ–‰๋  ๋•Œ ํ˜ธ์ถœ๋˜๋Š” ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ด๋ฒคํŠธ์— ์˜ํ•ด LogbackLoggingSystem ์œผ๋กœ์จ ๋กœ๊ทธ๋ฐฑ ์„ค์ •์ด ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.

<?xml version="1.0" encoding="UTF-8"?>

<!--
Base logback configuration provided for compatibility with Spring Boot 1.1
-->

<included>
	<include resource="org/springframework/boot/logging/logback/defaults.xml" />
	<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/spring.log}"/>
	<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
	<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
	<root level="INFO">
		<appender-ref ref="CONSOLE" />
		<appender-ref ref="FILE" />
	</root>
</included>

์œ„์™€ ๊ฐ™์ด ์„ค์ •๋˜์–ด์žˆ์–ด๋„ ๊ธฐ๋ณธ์ ์œผ๋กœ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋กœ๊ทธ๋Š” ์ฝ˜์†”์ด๋ผ๋Š” ํ‘œ์ค€ ์ถœ๋ ฅ์— ์˜ํ•ด ๊ธฐ๋ก๋˜๋Š” ํŽธ์ž…๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์šด์˜ํ•˜๋‹ค๋ณด๋ฉด ๋ณด์•ˆ ๊ฐ์‚ฌ ํ˜น์€ ๋น„์ฆˆ๋‹ˆ์Šค ๋™์ž‘์— ๋Œ€ํ•œ ๊ฒ€์ฆ์„ ์œ„ํ•ด ์ผ๋ถ€ ๋กœ๊ทธ๋ฅผ ๋ณ„๋„๋กœ ๋‚จ๊ฒจ์•ผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์š”๊ตฌ์‚ฌํ•ญ์ด ์žˆ๋‹ค๋ฉด ๊ธฐ๋ณธ์ ์ธ ๋กœ๊ทธ๋ฐฑ ์„ค์ • ๋ณด๋‹ค๋Š” ์šด์˜์„ ์œ„ํ•œ ์ปค์Šคํ…€ ๊ตฌ์„ฑ์„ ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

logback-spring.xml

When possible, we recommend that you use the -spring variants for your logging configuration (for example, logback-spring.xml rather than logback.xml). If you use standard configuration locations, Spring cannot completely control log initialization.

์Šคํ”„๋ง ๋ถ€ํŠธ ๊ณต์‹ ๋ฌธ์„œ์˜ Custom Log Configuration์— ๋Œ€ํ•œ ๋‚ด์šฉ์— ๋”ฐ๋ผ logback-spring.xml ์ด๋ผ๋Š” ํŒŒ์ผ๋ช…์œผ๋กœ ๋กœ๊ทธ๋ฐฑ์— ๋Œ€ํ•œ ์„ค์ • ํŒŒ์ผ์„ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒƒ์ด ํšจ์œจ์ ์ž…๋‹ˆ๋‹ค. Profile-specific Configuration์—์„œ ์„ค๋ช…ํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ๋ฐํƒœ๊ทธ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์†์„ฑ๊ฐ’์„ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ch.qos.logback.core.rolling.RollingFileAppender

์˜ค๋ฅ˜์— ๋Œ€ํ•œ ๋กœ๊ทธ๋งŒ ๋ณ„๋„๋กœ ์ถ”์ถœํ•˜์—ฌ ๊ธฐ๋กํ•œ๋‹ค๊ฑฐ๋‚˜ ํŠน์ • ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์— ๋Œ€ํ•œ ๋กœ๊ทธ๋ฅผ ๋ณ„๋„๋กœ ๋‚˜๋ˆ„์–ด์„œ ๊ด€๋ฆฌํ•˜๊ณ ์ž ํ•œ๋‹ค๋ฉด FileAppender ๋˜๋Š” RollingFileAppender๊ณผ ํ•จ๊ป˜ SizeAndTimeBasedRollingPolicy๋ฅผ ์ ์šฉํ•˜์—ฌ ์›ํ•˜๋Š” ์ถœ๋ ฅ ํ˜•ํƒœ๋กœ ๋กœ๊ทธ๊ฐ€ ๋‚จ๋„๋ก ๊ตฌ์„ฑํ•˜๋Š”๊ฒŒ ์ข‹์Šต๋‹ˆ๋‹ค.

<Configuration scan="true" scanPeriod="30 seconds">
    <include resource="org/springframework/boot/logging/logback/defaults.xml" />
    <include resource="org/springframework/boot/logging/logback/console-appender.xml" />

    <property name="ERROR_LOG_FILE" value="${LOG_PATH}/error_${LOG_FILE}"/>
    <appender name="ERROR_FILE" 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>
        <encoder>
            <pattern>${FILE_LOG_PATTERN}</pattern>
            <charset>${FILE_LOG_CHARSET}</charset>
        </encoder>
        <file>${ERROR_LOG_FILE}</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOGBACK_ROLLINGPOLICY_FILE_NAME_PATTERN:-${ERROR_LOG_FILE}.%d{yyyy-MM-dd}.%i.gz}</fileNamePattern>
            <cleanHistoryOnStart>${LOGBACK_ROLLINGPOLICY_CLEAN_HISTORY_ON_START:-false}</cleanHistoryOnStart>
            <maxFileSize>${LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE:-10MB}</maxFileSize>
            <totalSizeCap>${LOGBACK_ROLLINGPOLICY_TOTAL_SIZE_CAP:-0}</totalSizeCap>
            <maxHistory>${LOGBACK_ROLLINGPOLICY_MAX_HISTORY:-7}</maxHistory>
        </rollingPolicy>
    </appender>

    <root level="INFO">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="ERROR_FILE" />
    </root>
</Configuration>

๋ฆฌ๋ˆ…์Šค ์„œ๋ฒ„์˜ ๋กœ๊ทธ ๋กœํ…Œ์ด์…˜์„ ๋ณ„๋„๋กœ ํ™œ์šฉ์ค‘์ด๋ผ๋ฉด ๊ตณ์ด ๋กœ๊ทธ๋ฐฑ์—์„œ RollingFileAppender๋ฅผ ์‚ฌ์šฉํ•  ํ•„์š”๋Š” ์—†๋‹ค.

์œ„ ERROR_FILE appender๋Š” org/springframework/boot/logging/logback/file-appender.xml๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ž‘์„ฑํ•˜์˜€์œผ๋ฉฐ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์†์„ฑ์— ์˜ํ•ด ๊ฒฐ์ •๋œ LOG_PATH์— error_๋ฅผ ํŒŒ์ผ๋ช…์— ํฌํ•จํ•˜์—ฌ ๋‚จ๊ธฐ๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค.

์ฐธ๊ณ