[스프링SPRING]JDBC로그 라이브러리 설치

Log4Jdbc Log4j2 JDBC 4 » 1.16 설치

해당 라이브러리는 jdbc와 관련된 로그를 콘솔에 출력할 수 있다.

  • Log4Jdbc Log4j2 JDBC 4 » 1.16 복사하여 pom.xml에 붙여넣기
  • root-context.xml에서 아래 두 값을 변경해준다.
    • driverClassName의 value를 net.sf.log4jdbc.sql.jdbcapi.DriverSpy로 변경
    • url의 value를 jdbc:log4jdbc:mysql://localhost:3306/springdb?useSSL=false로 변경
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!-- DriverManagerDataSource 객체 -->
<!-- DataSource 정보를 가지고 있는 DriverManagerDataSource 객체를 생성 > -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- <property name="driverClassName"
value="com.mysql.jdbc.Driver"/>
<property name="url"
value="jdbc:mysql://localhost:3306/springdb?useSSL=false"/>-->
<property name="driverClassName"
value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"/>
<property name="url"
value="jdbc:log4jdbc:mysql://localhost:3306/springdb?useSSL=false"/>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>1234</value>
</property>
</bean>
<!-- DataSource 객체 end -->
  • log4jdbc.log4j2.properties파일과 logback.xml파일을 src/main/resources에 넣어준다
  • test실행시키면 앞으로 코드를 작성할때 log정보를 자세하게 확인할 수 있다. 원하는 출력값은 제일마지막줄의 윗줄에 나타난다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
INFO : jdbc.connection - 1. Connection opened
INFO : jdbc.audit - 1. Connection.new Connection returned
INFO : jdbc.audit - 1. Connection.getAutoCommit() returned true
INFO : jdbc.audit - 1. PreparedStatement.new PreparedStatement returned
INFO : jdbc.audit - 1. Connection.prepareStatement(select now()) returned net.sf.log4jdbc.sql.jdbcapi.PreparedStatementSpy@7004e3d
INFO : jdbc.sqlonly - select now()

INFO : jdbc.sqltiming - select now()
{executed in 0 msec}
INFO : jdbc.audit - 1. PreparedStatement.execute() returned true
INFO : jdbc.resultset - 1. ResultSet.new ResultSet returned
INFO : jdbc.audit - 1. PreparedStatement.getResultSet() returned net.sf.log4jdbc.sql.jdbcapi.ResultSetSpy@4b1abd11
INFO : jdbc.resultset - 1. ResultSet.getMetaData() returned com.mysql.jdbc.ResultSetMetaData@40021799 - Field level information:
com.mysql.jdbc.Field@4a1c0752[catalog=,tableName=,originalTableName=,columnName=now(),originalColumnName=,mysqlType=12(FIELD_TYPE_DATETIME),flags= BINARY, charsetIndex=63, charsetName=US-ASCII]
INFO : jdbc.resultset - 1. ResultSet.getType() returned 1003
INFO : jdbc.resultset - 1. ResultSet.next() returned true
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.ibatis.reflection.Reflector (file:/C:/Users/ITWILL/.m2/repository/org/mybatis/mybatis/3.4.1/mybatis-3.4.1.jar) to method java.lang.String.value()
WARNING: Please consider reporting this to the maintainers of org.apache.ibatis.reflection.Reflector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
INFO : jdbc.resultset - 1. ResultSet.getString(now()) returned 2020-10-15 15:24:24.0
INFO : jdbc.resultset - 1. ResultSet.wasNull() returned false
INFO : jdbc.resultsettable -
|----------------------|
|now() |
|----------------------|
|2020-10-15 15:24:24.0 |
|----------------------|

INFO : jdbc.resultset - 1. ResultSet.next() returned false
INFO : jdbc.resultset - 1. ResultSet.close() returned void
INFO : jdbc.audit - 1. PreparedStatement.getConnection() returned net.sf.log4jdbc.sql.jdbcapi.ConnectionSpy@4f20a5e0
INFO : jdbc.audit - 1. Connection.getMetaData() returned com.mysql.jdbc.JDBC4DatabaseMetaData@54da32dc
INFO : jdbc.audit - 1. PreparedStatement.getMoreResults() returned false
INFO : jdbc.audit - 1. PreparedStatement.getUpdateCount() returned -1
INFO : jdbc.audit - 1. PreparedStatement.close() returned
INFO : jdbc.connection - 1. Connection closed
INFO : jdbc.audit - 1. Connection.close() returned
2020-10-15 15:24:24.0
INFO : org.springframework.context.support.GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext@5f16132a: startup date [Thu Oct 15 15:24:24 KST 2020]; root of context hierarchy

Comments