[SpringBoot] MyBatis + log4jdbc 설정 시 deprecated 로그 수정
MyBatis에 보다 친절한(?) 로그 출력을 log4jdbc 통해서 가능하대서 적용해봤는데.
빌드 시 로그에 다음과 같은 로그를 찍고 있드라.
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
악! 왜 갑자기 이게 나오지??
가만보자.. 내가 추가한게 뭐였드라?
(사실 에러 로그가 아니기 때문에 큰 문제는 아니지만 거슬린다 ㅠㅠ)
log4jdbc.log4j2.Properties 파일..
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.dump.sql.maxlinelength=0
build.gradle 파일..
...
implementation 'org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4:1.16' /* log4jdbc 사용을 위한 의존성 셋팅 */
...
application.properties 파일..
...
# MySQL setting
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#spring.datasource.url=jdbc:mysql://localhost:3306/testdb
spring.datasource.driver-class-name=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
spring.datasource.url=jdbc:log4jdbc:mysql://localhost:3306/testdb?useSSL=false&useUnicode=true&serverTimezone=Asia/Seoul
...
가만보자... 기존에 com.mysql.cj.jdbc.Driver 설정했던 부분 주석처리하고 net.sf.log4jdbc.sql.jdbcapi.DriverSpy를 추가했는데,
요놈이 내부적으로 com.mysql.jdbc.Driver 를 쓰나보네..
그러면 com.mysql.cj.jdbc.Driver 를 명시적으로 추가해줘야하는디.. 어떻게 하나..
바로!
log4jdbc.log4j2.Properties 에 이어서 명시적으로 추가해준다.
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.dump.sql.maxlinelength=0
# Driver 설정 추가
log4jdbc.drivers=com.mysql.cj.jdbc.Driver
log4jdbc.auto.load.popular.drivers=false
위와 같이 log4jdbc.drivers 를 com.mysql.cj.jdbc.Driver 로 설정 후 다시 빌드하면 해당 로그는 출력되지 않는다.
끝.
ref)
https://happy-jjang-a.tistory.com/159
SpringBoot Log4jdbc 를 사용한 Mybatis 쿼리 로그 출력
SpringBoot에서 log4jdbc를 사용하면 SQL문 로그를 좀 더 가시적으로 출력할 수 있다. SQL문에 들어가는 파라메타도 바인딩이 되어 출력이 되고, 결과도 테이블 형태로 출력되어 보기가 편해진다. 1. log4
happy-jjang-a.tistory.com
https://makeaplayground.tistory.com/179
Spring Boot SQL 로그 설정 (Log4jdbc) Gradle 적용시키기
Log4jdbc Log4j를 JDBC와 연결하여 사용하기 위해 만들어진 오픈소스 프로젝트이다 Log4jdbc는 예전 버전이고 Log4j2와 Slf4j와 연동되는 버전이 나왔다 Log4jdbc-log4j2 적용법 1. 의존성 주입 - build.gradle에 Log4
makeaplayground.tistory.com