spring boot ์ ํ๋ฆฌ์ผ์ด์ ์์ ๋นผ๋์ ์ ์๋ ๊ฒ์ด ๋ฐ๋ก logging ์ด๋ค. spring boot logging ์ค์ ๋ฐฉ๋ฒ๊ณผ ํ๋กํ์ผ๋ณ logging์ ๋ถ๋ฆฌํ๋ ๋ฐฉ๋ฒ๋ฑ์ ๋ํด์ ์ ๋ฆฌํด ๋ณด์๋ค.
Spring Boot์๋ ์ผ๋ฐ์ ์ผ๋ก Spring ํ๋ ์์ํฌ์ spring-jcl ๋ชจ๋์์ ์ ๊ณตํ๋ Commons Logging API๋ฅผ ์ ์ธํ๊ณ ๋ ํ์ ๋ก๊น
์ข
์์ฑ์ด ์๋ค. Logback์ ์ฌ์ฉํ๋ ค๋ฉด ํด๋์ค ๊ฒฝ๋ก์ Logback๊ณผ spring-jcl์ ํฌํจ์์ผ์ผ ํ๋ค.
์ด๋ฅผ ์ํด์ spring-boot-sterter-logging ์ข
์์ฑ์ ์ถ๊ฐํ๋ฉด ๋๋ค. ์น ์ ํ๋ฆฌ์ผ์ด์
์ ๊ฒฝ์ฐ spring-boot-starter-web์ด spring-boot-starter-logging ์ข
์์ฑ์ ํฌํจํ๊ณ ์๊ธฐ ๋๋ฌธ์ spring-boot-starter-web ์ข
์์ฑ๋ง ์ถ๊ฐํ๋ฉด Logback์ ์ฌ์ฉํ ์ ์๋ค.

์ ํํ๊ฒ ๋งํ์๋ฉด spring-boot-starter-logging ์์กด์ฑ์ spring-boot-starter ์์กด์ฑ์ ํฌํจ๋์ด ์๊ณ
spring-boot-starter-web ์์กด์ฑ์ด spring-boot-starter ์์กด์ฑ์ ํฌํจํ๊ณ ์๋ค.
Spring Boot์๋ ํด๋์ค ๊ฒฝ๋ก์ ๋ด์ฉ์ ๊ธฐ๋ฐ์ผ๋ก ๋ก๊น
์ ๊ตฌ์ฑํ๋ ค๊ณ ์๋ํ๋ LoggingSystem ์ถ์ํ๊ฐ ์๋ค.
Logback์ ์ฌ์ฉํ ์ ์๋ ๊ฒฝ์ฐ Logback์ด ์ฒซ ๋ฒ์งธ๋ก ์ ํ๋์ด ์ฌ์ฉ๋๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก Spring Boot๋ ์์คํ
์ ๊ธฐ๋ณธ ์์น์์ ๋ค์ดํฐ๋ธ ๊ตฌ์ฑ์ ์ ํํ์ง๋ง(Logback์ ๊ฒฝ์ฐ classpath:logback.xml), logging.config ์์ฑ์ ์ฌ์ฉํ์ฌ ๊ตฌ์ฑ ํ์ผ์ ์์น๋ฅผ ์ค์ ํ ์ ์๋ค.
spring boot logging ํ์ผ ์ถ๋ ฅ
๊ธฐ๋ณธ์ ์ผ๋ก Spring Boot๋ ์ฝ์์๋ง ๋ก๊น
ํ๊ณ ๋ก๊ทธ ํ์ผ์ ์์ฑํ์ง ์๋๋ค. ์ฝ์ ์ถ๋ ฅ ์ด์ธ์ ๋ก๊ทธ ํ์ผ์ ๊ธฐ๋กํ๋ ค๋ฉด logging.file.name ๋๋ logging.file.path ์์ฑ์ ์ค์ ํด์ผ ํ๋ค.
๋ํดํธ๋ก ๋ก๊ทธ ํ์ผ์ rotate ์ฌ์ด์ฆ๋ 10MB์ด๋ฉฐ ๋ก๊ทธ ๋ ๋ฒจ์ ERROR, WARN, INFO ๋ ๋ฒจ ๋ก๊ทธ๊ฐ ๊ธฐ๋ก๋๋ค.
logging.file.name ์์ฑ
์ง์ ๋ ๋ก๊ทธ ํ์ผ์ ๋ก๊ทธ๋ฅผ ๊ธฐ๋กํ๋ค. ์ค์ ์ ์ ๋ ๊ฒฝ๋ก ํน์ ์๋ ๊ฒฝ๋ก๊ฐ ๋ ์ ์๋ค.
logging:
file:
name: log/application.logYAMLํ์ฌ ๋๋ ํฐ๋ฆฌ๋ฅผ ๊ธฐ์ค์ผ๋ก log/application.log ํ์ผ์ ๋ก๊ทธ๋ฅผ ๊ธฐ๋กํ๋ค.
logging.file.path ์์ฑ
์ง์ ๋ ๋๋ ํฐ๋ฆฌ์ spring.log ํ์ผ์ ๊ธฐ๋กํ๋ค. ์ค์ ์ ์ ๋ ๊ฒฝ๋ก ํน์ ์๋ ๊ฒฝ๋ก๊ฐ ๋ ์ ์๋ค.
logging:
file:
path: logYAMLํ์ฌ ๋๋ ํฐ๋ฆฌ๋ฅผ ๊ธฐ์ค์ผ๋ก log/spring.log ํ์ผ์ ๋ก๊ทธ๋ฅผ ๊ธฐ๋กํ๋ค.
logging.* ์์ฑ์ ์ค์ ๋ก ์ฌ์ฉ๋๋ ๋ก๊น ์ธํ๋ผ์๋ ๋ ๋ฆฝ์ ์ด๋ค. ๋ฐ๋ผ์ ํน์ ๊ตฌ์ฑ ํค
(์: ๋ก๊ทธ๋ฐฑ์ ์ํ logback.configurationFile)๋ Spring Boot์์ ๊ด๋ฆฌ๋์ง ์๋๋ค.
spring boot logging ํ์ผ Rotation
Logback์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ application.properties ํน์ application.yml ํ์ผ์ ์ฌ์ฉํ์ฌ ๋ก๊ทธ lotation ์ค์ ์ ์์ธํ๊ฒ ํ ์ ์๋ค. ๊ทธ ์ธ ๋ค๋ฅธ ๋ชจ๋ ๋ก๊น
์์คํ
์ ๊ฒฝ์ฐ ์ง์ rotation ์ค์ ์ ๊ตฌ์ฑํด์ผ ํ๋ค.
(ex. Log4j2๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ log4j2.xml ๋๋ log4j2-spring.xml ํ์ผ์ ์ค์ ์ ์ถ๊ฐํ ์ ์๋ค.)
์ง์๋๋ rotation ์ ์ฑ
์ค์ ์ ์๋์ ๊ฐ๋ค.
| logging.logback.rollingpolicy.file-name-pattern | The filename pattern used to create log archives. |
|---|---|
| logging.logback.rollingpolicy.clean-history-on-start | If log archive cleanup should occur when the application starts. |
| logging.logback.rollingpolicy.max-file-size | The maximum size of log file before it is archived. |
| logging.logback.rollingpolicy.total-size-cap | The maximum amount of size log archives can take before being deleted. |
| logging.logback.rollingpolicy.max-history | The maximum number of archive log files to keep (defaults to 7). |
spring boot logging ๋ก๊ทธ ๋ ๋ฒจ
์ง์๋๋ ๋ชจ๋ ๋ก๊น
์์คํ
์ logging.level.<logger>=<๋ก๊ทธ๋ ๋ฒจ>์ ์ฌ์ฉํ์ฌ application.yml ํน์ application.properties ์์ ๋ก๊ทธ ๋ ๋ฒจ์ ์ค์ ํ ์ ์๋ค.
๋ก๊ทธ ๋ ๋ฒจ์ TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF ๊ฐ ์ง์๋๋ฉฐ root ๋ก๊ฑฐ๋ logging.level.root๋ก ์ค์ ํ๋ค.
logging:
level:
root: "warn"
org.springframework.web: "debug"
org.hibernate: "error"YAML๋ก๊ทธ ๋ ๋ฒจ์ ํ๊ฒฝ ๋ณ์๋ก๋ ์ค์ ์ด ๊ฐ๋ฅํ๋ค.
ํ๊ฒฝ ๋ณ์ LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_WEB=DEBUG๋ logging.level.org.springframework.web=DEBUG์ ๋์ผํ๊ฒ ๋์ํ๋ค.
ํ์ง๋ง ํ๊ฒฝ ๋ณ์์ ์ ๊ทผ ๋ฐฉ์์ ํจํค์ง ์์ค ๋ก๊น
์ค์ ์์๋ง ๋์ํ๋ค. ๋ฆด๋์ค ๋ฐ์ธ๋ฉ์ ํญ์ ํ๊ฒฝ ๋ณ์๋ฅผ ์๋ฌธ์๋ก ๋ณํํ๊ธฐ ๋๋ฌธ์ ์ด๋ฌํ ๋ฐฉ์์ผ๋ก ๊ฐ๋ณ ํด๋์ค์ ๋ํ ๋ก๊น
์ ๊ตฌ์ฑํ ์ ์๋ค.
spring boot logging ๋ก๊ทธ ๊ทธ๋ฃน
์ฌ๋ฌ ๋ก๊น ๋์ ํจํค์ง๋ฅผ ํ๋์ ๋ก๊ทธ ๊ทธ๋ฃน์ผ๋ก ์ ์ํ ์ ์๋ค.
logging:
group:
tomcat: "org.apache.catalina,org.apache.coyote,org.apache.tomcat"
level:
tomcat: "trace"YAMLSpring Boot์์๋ ์ฌ์ ์ ์ ์๋ ๋ก๊น ๊ทธ๋ฃน์ด ํฌํจ๋์ด ์๋ค.
| web | org.springframework.core.codec org.springframework.http org.springframework.web org.springframework.boot.actuate.endpoint.web org.springframework.boot.web.servlet.ServletContextInitializerBeans |
|---|---|
| sql | org.springframework.jdbc.core org.hibernate.SQL org.jooq.tools.LoggerListener |
spring boot logging Custom Log Configuration
application.yml ์์ ์ง์ํ๋ ๋ก๊น
๊ด๋ จ ์ค์ ์ธ์ Logback์ ์ฌ์ฉ์ ์ง์ ์ค์ ์ ์ ์ฉํด์ผ ํ๋ ๊ฒฝ์ฐ ํ์ค Logback ๊ตฌ์ฑ ํ์ผ์ ์ถ๊ฐํด์ผ ํ๋ค. Logback์ด ์ฐพ์ ์ ์๋๋ก classpath root์ logback.xml ํ์ผ์ ์ถ๊ฐํ ์ ์๋ค.
Spring Boot Logback ํ์ฅ์ ์ฌ์ฉํ๋ ค๋ ๊ฒฝ์ฐ logback-spring.xml์ ์ฌ์ฉํ ์๋ ์๋ค.
org.springframework.boot.logging.LoggingSystem ์์คํ
์์ฑ์ ์ฌ์ฉํ์ฌ Spring Boot์์ ํน์ ๋ก๊น
์์คํ
์ ์ฌ์ฉํ๋๋ก ๊ฐ์ ํ ์ ์๋ค. ๊ฐ์ LoggingSystem ๊ตฌํ์ ์ ๊ทํ๋ ํด๋์ค ์ด๋ฆ์ด์ด์ผ ํ๋ค. ๊ฐ์ none์ผ๋ก ์ฌ์ฉํ์ฌ Spring Boot์ ๋ก๊น
๊ตฌ์ฑ์ ๋นํ์ฑํํ ์๋ ์๋ค.
Log4J2LoggingSystem์ ์ฌ์ฉํ๋ ค๋ ๊ฒฝ์ฐ์๋ ์๋ ์ข
์์ฑ์ด ํ์ํ๋ค.
<!--
log4j2 ๋ก๊น
์์คํ
์ ์ฌ์ฉํ๋ ค๋ ๊ฒฝ์ฐ
spring-boot-starter-logging ์ข
์์ฑ์ ์ ๊ฑฐํ์ง ์์ผ๋ฉด
class org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค.
๊ทธ๋ฅ Spring Boot์์ ๊ธฐ๋ณธ์ผ๋ก ์ ์ฉ๋๋ Logback ๋ก๊น
์์คํ
์ ์ฌ์ฉํ๋ ๊ฒ์ ์ ์ผ
์ข์ ๊ฒ ๊ฐ๋ค.
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>XMLLog4J2LoggingSystem์ ์ฌ์ฉํ๋๋ก ์ค์
-Dorg.springframework.boot.logging.LoggingSystem=org.springframework.boot.logging.log4j2.Log4J2LoggingSystem
LogbackLoggingSystem์ ์ฌ์ฉํ๋๋ก ์ค์ (default)
-Dorg.springframework.boot.logging.LoggingSystem=org.springframework.boot.logging.logback.LogbackLoggingSystem
JavaLoggingSystem์ ์ฌ์ฉํ๋๋ก ์ค์
-Dorg.springframework.boot.logging.LoggingSystem=org.springframework.boot.logging.java.JavaLoggingSystemPlaintext์์คํ
์์ฑ์ ๋ํ ์ฒ๋ฆฌ๋ org.springframework.boot.context.logging.LoggingApplicationListener ํด๋์ค์์ ์ฒ๋ฆฌํ๋ค.
๊ฐ ๋ก๊น
์์คํ
์ ์๋ ํ์ ๊ฐ์ด ํ์ผ์ ๋ก๋ฉํ๋ค.
| Logging System | Customization |
|---|---|
| Logback (LogbackLoggingSystem) | logback-spring.xml, logback-spring.groovy, logback.xml ํน์ logback.groovy |
| Log4j2 (Log4J2LoggingSystem) | log4j2-spring.xml ํน์ log4j2.xml |
| Java (JavaLoggingSystem) | logging.properties |
ํ์ค ๊ตฌ์ฑ ์์น๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ Spring์ด ๋ก๊ทธ ์ด๊ธฐํ๋ฅผ ์์ ํ ์ ์ดํ ์ ์๊ธฐ ๋๋ฌธ์ ๊ฐ๋ฅํ๋ฉด ๋ก๊น ๊ตฌ์ฑ์ -spring suffix๊ฐ ๋ถ์ ํ์ผ์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข๋ค.
์คํ ๊ฐ๋ฅํ jar์์ ์คํํ ๋ Java Util Logging ํด๋์ค ๋ก๋ฉ์ ๋ฌธ์ ๊ฐ ์๋ค. ๊ฐ๊ธ์ ์คํ ๊ฐ๋ฅํ jar์์ ์คํํ ๋๋ ์ด๋ฅผ ํผํ๋ ๊ฒ์ด ์ข๋ค.
์ฌ์ฉ์ ์ ์ ์ค์ ์ ์ํด์ ์ผ๋ถ ์ค์ ํญ๋ชฉ์ Spring ํ๊ฒฝ์์ system property๋ก ์ ์ก๋๋ค. system property๋ก ์ ์ก๋๋ property๋ ์ฌ์ฉ์ ์ ์ ๋ก๊น
์ค์ ์์ ์ฌ์ฉํ ์ ์๋ค.
์๋ฅผ ๋ค์ด application.yml ์์ logging.file.path ์ค์ ์ LOG_PATH system property๋ก ์ ์ก๋๊ณ ์ฌ์ฉ์ ์ ์ ์ค์ ์์๋ ${LOG_PATH} (=logging.file.path)์ ๊ฐ์ ํํ๋ก ์ฌ์ฉํ ์ ์๋ค.
๋ํ logging.file.path๋ ํ๊ฒฝ ๋ณ์ LOGGING_FILE_PATH์ ๋งตํ๋๋ฏ๋ก LOGGING_FILE_PATH ํ๊ฒฝ ๋ณ์ ์ญ์ LOG_PATH system property๋ก ์ ์ก๋์ด ์ฌ์ฉ์ ์ ์ ๋ก๊น
์ค์ ์์ ์ฌ์ฉํ ์ ์๋ค.
system property๋ก ์ ์ก๋๋ ์์ฑ์ ์๋์ ๊ฐ๋ค.
| Spring Environment | System Property | Comments |
|---|---|---|
| logging.exception-conversion-word | LOG_EXCEPTION_CONVERSION_WORD | The conversion word used when logging exceptions. |
| logging.file.name | LOG_FILE | If defined, it is used in the default log configuration. |
| logging.file.path | LOG_PATH | If defined, it is used in the default log configuration. |
| logging.pattern.console | CONSOLE_LOG_PATTERN | The log pattern to use on the console (stdout). |
| logging.pattern.dateformat | LOG_DATEFORMAT_PATTERN | Appender pattern for log date format. |
| logging.charset.console | CONSOLE_LOG_CHARSET | The charset to use for console logging. |
| logging.threshold.console | CONSOLE_LOG_THRESHOLD | The log level threshold to use for console logging. |
| logging.pattern.file | FILE_LOG_PATTERN | The log pattern to use in a file (if LOG_FILE is enabled). |
| logging.charset.file | FILE_LOG_CHARSET | The charset to use for file logging (if LOG_FILE is enabled). |
| logging.threshold.file | FILE_LOG_THRESHOLD | The log level threshold to use for file logging. |
| logging.pattern.level | LOG_LEVEL_PATTERN | The format to use when rendering the log level (default %5p). |
| PID | PID | The current process ID (discovered if possible and when not already defined as an OS environment variable). |
Logback์ ์ฌ์ฉํ๋ค๋ฉด ์๋ ์์ฑ๋ค๋ system property๋ก ์ ์ก๋๋ค.
| Spring Environment | System Property | Comments |
|---|---|---|
| logging.logback.rollingpolicy.file-name-pattern | LOGBACK_ROLLINGPOLICY_FILE_NAME_PATTERN | Pattern for rolled-over log file names (default ${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz). |
| logging.logback.rollingpolicy.clean-history-on-start | LOGBACK_ROLLINGPOLICY_CLEAN_HISTORY_ON_START | Whether to clean the archive log files on startup. |
| logging.logback.rollingpolicy.max-file-size | LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE | Maximum log file size. |
| logging.logback.rollingpolicy.total-size-cap | LOGBACK_ROLLINGPOLICY_TOTAL_SIZE_CAP | Total size of log backups to be kept. |
| logging.logback.rollingpolicy.max-history | LOGBACK_ROLLINGPOLICY_MAX_HISTORY | Maximum number of archive log files to keep. |
Logback์ ์ํ Logging ์ค์
Spring Boot์๋ ๊ณ ๊ธ ๊ตฌ์ฑ์ ๋์์ด ๋ ์ ์๋ Logback์ ๋ํ ์ฌ๋ฌ ๊ฐ์ง ํ์ฅ์ด ํฌํจ๋์ด ์๋ค. logback-spring.xml ๊ตฌ์ฑ ํ์ผ์์ ์ด๋ฌํ ํ์ฅ์ ์ฌ์ฉํ ์ ์๋ค.
ํ์ค logback.xml ๊ตฌ์ฑ ํ์ผ์ ๋๋ฌด ์ผ์ฐ ๋ก๋๋๋ฏ๋ก ์ด ํ์ผ์์ ํ์ฅ์ ์ฌ์ฉํ ์ ์๋ค. logback-spring.xml ํ์ผ์ ๊ตฌ์ฑํ๊ฑฐ๋ logging.config ์์ฑ์ ํ์ฅ ์ค์ ํ์ผ์ ์ ์ํด์ผ ํ๋ค.
Profile ์ง์ ์ค์
<springProfile> ํ๊ทธ๋ฅผ ์ฌ์ฉํ๋ฉด ํ์ฑ Spring ํ๋กํ์ผ์ ๊ธฐ๋ฐ์ผ๋ก ๊ตฌ์ฑ ์น์
์ ์ ํ์ ์ผ๋ก ํฌํจํ๊ฑฐ๋ ์ ์ธํ ์ ์๋ค. ํ๋กํ์ผ ์น์
์ <configuration> ์์ ๋ด ์ด๋์์๋ ์ง์๋๋ค. name ์์ฑ์ ์ฌ์ฉํ์ฌ ๊ตฌ์ฑ์ ์๋ฝํ๋ ํ๋กํ์ผ์ ์ง์ ํ๋ค.
<springProfile> ํ๊ทธ์๋ ํ๋กํ์ผ ์ด๋ฆ ๋๋ ํ๋กํ์ผ ํํ์์ด ํฌํจ๋ ์ ์๋ค. ํ๋กํ์ผ ํํ์์ ์ฌ์ฉํ๋ฉด ๋ณด๋ค ๋ณต์กํ ํ๋กํ์ผ ๋ก์ง์ ํํํ ์ ์๋ค.
<springProfile name="staging">
<!-- configuration to be enabled when the "staging" profile is active -->
</springProfile>
<springProfile name="dev | staging">
<!-- configuration to be enabled when the "dev" or "staging" profiles are active -->
</springProfile>
<springProfile name="!production">
<!-- configuration to be enabled when the "production" profile is not active -->
</springProfile>
XMLEnvironment ์์ฑ
<springProperty> ํ๊ทธ๋ฅผ ์ฌ์ฉํ๋ฉด Spring ํ๊ฒฝ์ ์์ฑ์ logback ๋ด์์ ์ฌ์ฉํ ์ ์๋ค.
์ด ํ๊ทธ๋ logback ๊ตฌ์ฑ์์ application.properties ํน์ application.yml์ ๊ฐ์ ์ฌ์ฉํ๋ ค๋ ๊ฒฝ์ฐ์ ์ ์ฉํ๋ค.
์ด ํ๊ทธ๋ logback ํ์ค <property> ํ๊ทธ์ ๋น์ทํ ๋ฐฉ์์ผ๋ก ๋์ํ๋ค. ํ์ง๋ง ์ง์ ๊ฐ์ ์ง์ ํ๋ ๋์ ์ Spring property์ source ํ๊ฒฝ์ ์ง์ ํ๋ค.
Spring property๊ฐ ์ค์ ๋์ง ์์ ๊ฒฝ์ฐ defaultValue ์์ฑ์ ์ฌ์ฉํ์ฌ default ๊ฐ์ ์ง์ ํ ์ ์๋ค.
<springProperty scope="context" name="fluentHost" source="myapp.fluentd.host"
defaultValue="localhost"/>
<appender name="FLUENT" class="ch.qos.logback.more.appenders.DataFluentAppender">
<remoteHost>${fluentHost}</remoteHost>
...
</appender>XMLsource ์์ฑ์ kebab case(ex. property-name)๋ก ์ง์ ํด์ผ ํ๋ค.
Configure Logback for Logging
Spring Boot๋ ์์ฒด ๊ตฌ์ฑ์ ํฌํจํ ์ ์๋ ๋ค์ํ logback ๊ตฌ์ฑ์ ์ ๊ณตํ๋ค. ์ด๋ฌํ ๊ตฌ์ฑ์ ํน์ ์ผ๋ฐ์ ์ธ Spring Boot ๊ท์น์ ๋ค์ ์ ์ฉํ ์ ์๋๋ก ์ค๊ณ๋์๋ค.
org.springframework.boot:spring-boot ์ข
์์ฑ์ ํฌํจ๋ org/springframework/boot/logging/logback/ ๊ฒฝ๋ก์ ์ ๊ณต๋๋ ํ์ผ์ ์๋์ ๊ฐ๋ค.
- defaults.xml – ๋ณํ ๊ท์น, ํจํด ์์ฑ ๋ฐ ์ผ๋ฐ์ ์ธ ๋ก๊ฑฐ ๊ตฌ์ฑ์ ์ ๊ณตํ๋ค.
- console-appender.xml – ์ฝ์ ๋ก๊ทธ ํจํด์ ์ฌ์ฉํ์ฌ ConsoleAppender๋ฅผ ์ถ๊ฐํ๋ค.
- file-appender.xml – FILE_LOG_PATTERN ๋ฐ ROLLING_FILE_NAME_PATTERN system ์์ฑ๊ณผ ํจ๊ป RollingFileAppender๋ฅผ ์ถ๊ฐํ๋ค.
- base.xml – ์ด์ ๋ฒ์ ์ Spring Boot์์ ํธํ์ฑ์ ์ํด ์ ๊ณต๋๋ค.
logback-spring.xml ํ์ผ์๋ ๋ค์๊ณผ ๊ฐ์ด Spring Boot์์ ๊ธฐ๋ณธ์ ์ผ๋ก ์ ๊ณต๋๋ ํ์ผ์ include ํ์ฌ ์ฌ์ฉํ ์ ์๋ค.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
<logger name="org.springframework.web" level="DEBUG"/>
</configuration>XMLConfigure Logback for File-only Output
console ๋ก๊น ์ ๋นํ์ฑํํ๊ณ ์ถ๋ ฅ์ ํ์ผ์๋ง ์ฐ๋ ค๋ฉด ์๋ ์์์ ๊ฐ์ด console-appender.xml์ด ์๋ file-appender.xml์ ๊ฐ์ ธ์ค๋ ์ฌ์ฉ์ ์ ์ logback-spring.xml ์ด ํ์ํ๋ค.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<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/file-appender.xml" />
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>XML์ ์์์์๋ ${LOG_FILE} system property๋ฅผ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ logging.file.name ์ค์ ์ด ํ์ํ๋ค.
{LOG_FILE}์ด ์๋ ๊ฒฝ์ฐ {LOG_PATH}๋ฅผ ์ฌ์ฉํ๊ณ ์์ผ๋ฉด ${LOG_TEMP}๋ฅผ ์ฌ์ฉํ๋ ์์ด๋ค.
logging:
file:
name: "myapplication.log"YAML์ง๊ธ๊น์ง Spring Boot์ ๊ธฐ๋ณธ ๋ก๊น ์ ๋ํ ์ ๋ฆฌ์ Logback ํ์ฅ ์ค์ ์ ๋ํด์ ๊ฐ๋จํ ์์๋ณด์๋ค.
ํจ๊ป ๋ณด๋ฉด ์ข์ ๊ธ
Spring Boot Logback(๋ก๊ทธ๋ฐฑ) ์ค์ , ์ด ๊ธ ํ๋๋ก ๋๋ด์ธ์!!
์ฐธ๊ณ ๋งํฌ
https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.logging
https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.logging
