728x90
아래 내용은 https://github.com/beaver84/setting-test 에서 실제 소스를 확인할 수 있습니다.
- Logback 의존성 추가
implementation 'org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1:1.16'
- application.properties 에 설정 추가
logging.level.root=debug
logging.level.org.springframework.web=DEBUG
logging.config=classpath:logback-local.xml
- logback-local.xml 파일 추가
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds"> // 30초마다 자동 리로드 설정
<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!-- <Pattern>%d{[yyyy.MM.dd HH:mm:ss.SSS]} [%-5level] [%thread] %msg \(%F:%L\) %n</Pattern> -->
<Pattern>%green(%d{ISO8601}) %highlight(%-5level) [%magenta(%t)] %cyan(%logger{100}): %msg%n%throwable
</Pattern>
<!-- <Pattern>%d{[yyyy.MM.dd HH:mm:ss.SSS]} [%-5p] %m (%F:%L)%n</Pattern>//-->
</encoder>
</appender>
<appender name="hibernate" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%green(%d{ISO8601}) %highlight(%-5level) [%magenta(%t)] %cyan(%logger{100}): %msg%n%throwable
</pattern>
</encoder>
<filter class="com.example.settingtest.utils.LogFilter"/>
</appender>
<logger name="org.springframework.core" level="DEBUG" additivity="false">
<appender-ref ref="consoleAppender"/>
</logger>
<logger name="reactor.netty.http.client" level="DEBUG" additivity="false">
<appender-ref ref="consoleAppender"/>
</logger>
<logger name="org.springframework.boot" level="DEBUG" additivity="false">
<appender-ref ref="consoleAppender"/>
</logger>
<logger name="org.springframework.web" level="DEBUG" additivity="false">
<appender-ref ref="consoleAppender"/>
</logger>
<logger name="org.apache.ibatis" level="DEBUG" additivity="false">
<appender-ref ref="consoleAppender"/>
</logger>
<logger name="jdbc.sqltiming" level="DEBUG" additivity="false">
<appender-ref ref="hibernate"/>
</logger>
<logger name="com.example.settingtest" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="consoleAppender"/>
</logger>
<logger name="jdbc" level="OFF"/>
<logger name="jdbc.connection" level="OFF"/>
<logger name="jdbc.sqlonly" level="OFF"/>
<logger name="jdbc.audit" level="OFF"/>
<logger name="jdbc.resultset" level="OFF"/>
<logger name="jdbc.resultsettable" level="OFF"/>
</configuration>
- 특정 로그 처리에 대해 FIlter를 확장하여 직접 개발
public class LogFilter extends Filter<ILoggingEvent> {
@Override
public FilterReply decide(ILoggingEvent event) {
if (event.getMessage().contains("select 1") || event.getThreadName().contains("commons-pool-evictor-thread")) {
return FilterReply.DENY;
}
return FilterReply.NEUTRAL;
}
}
// XML에서는 아래와 같이 설정
// <filter class="com.example.settingtest.utils.LogFilter"/>
728x90
- 설정 전
- 설정 후
728x90
'Spring > 초기 setting' 카테고리의 다른 글
10) Spring Data Redis 셋팅 (0) | 2023.04.20 |
---|---|
9) 비밀번호 암/복호화(Encrypt/Decrypt) 설정 (0) | 2023.04.20 |
8) API Response(@ControllerAdvice) 설정 (0) | 2023.04.20 |
mapStruct 소개 및 활용 (0) | 2023.04.10 |
6) 스프링 시큐리티(spring-security) 적용 (0) | 2023.04.05 |