๐Logger ์ ์ธ ๋ฐ ์ด๊ธฐํ
private final Logger log = LoggerFactory.getLogger(GlobalExceptionAdvise.class);
final๋ก ์ ์ธํด์ ์ด๋์๋ log ์ถ๋ ฅ ๊ฐ๋ฅ!
๐Log level
trace, debug, info, warn, error
procteced ResponseEntity<Object> handleBindException(...){
log.error(String.format();
}
์์ธ์ฒ๋ฆฌ ํ ๋๋ log.error ๋ก ํ๊ณ
์๋ฌ๊ฐ ์๋ ๋๋ Log level์ info ๊ฐ์ ๊ฑธ๋ก ํ๋ค!
Log level์ด debug์ผ๋ก ํ ๋๋ ์๋์ ๊ฐ์ด ํ๋ฉด ๋๋ค.
application.yml
logging:
level:
root: debug
์ ์ฝ๋๋ฅผ ์ถ๊ฐํ๋ฉด ๋๋ฒ๊ทธ ์์ธ ๋ด์ฉ์ด ๋ค ์ถ๋ ฅ๋๋ค.
logback.xml
<configuration scan = "true">
<!-- file์๋ค๊ฐ ๋ก๊ทธ๋ฅผ ๋จ๊ธฐ๋ appender ์ถ๊ฐ-->
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>log/logFile.%d{yyyy-MM-dd}-%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<Pattern>%d %-5level --- [%thread] - %msg%n</Pattern>
</encoder>
</appender>
<!-- appender ์ถ๊ฐ -->
<appender name = "console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!-- %d: ๋ ์ง, [%-5level] : ๋ก๊ทธ ๋ ๋ฒจ, %msg: ๋ก๊ทธ ๋ฉ์ธ์ง, %n: ๊ฐํ-->
<Pattern>%d [%-5level] - %msg %n</Pattern>
</encoder>
</appender>
<!-- appender์ ์ฌ์ฉํ๊ธฐ ์ํ ์ค์ -->
<!-- INFO ๋ ๋ฒจ ์ด์์ธ ๊ฒ๋ค๋ง ์ถ๋ ฅ-->
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="file"/>
</root>
</configuration>
๐์คํ๊ฒฐ๊ณผ
์ ์ฝ๋๋ฅผ ์ถ๊ฐํด์ ํ๋ก์ ํธ๋ฅผ ์คํํ๋ฉด ๋ฐ ๊ทธ๋ฆผ์ฒ๋ผ log๋ผ๋ ํด๋ ๋ฐ์ log๋ค์ด ์ ์ฅ๋ file์ ๋ณผ ์ ์๋ค.
'โก๐ฉโ๐ป โก > ยบSpring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Spring] ๊ฒฐ์ ์๋น์ค | ํฌํธ์ ์ฐ๊ฒฐํ๊ธฐ (1) | 2024.01.02 |
---|---|
[Spring] application.yml ์ค์ ํ์ผ (0) | 2023.12.28 |
[Spring] AOP(Aspect Oriented Programming) ๊ด์ ์งํฅ ํ๋ก๊ทธ๋๋ฐ (0) | 2023.12.27 |
[Spring] JPA(Hibernate)์ ์ด์ฉํ ์ ๋ ฅ๊ฐ ๊ฒ์ฆ (0) | 2023.12.26 |
[Spring] ์คํ๋ง ๋ฌธ์ํ(Spring DOC) - Swagger UI (0) | 2023.12.26 |