본문 바로가기

카테고리 없음

log4j 뷰티 쿼리

참고자료 : https://code.google.com/p/log4jdbc/


log4jdbc는 SQL 로그를 보다 인간적으로 볼 수 있게 해 주는 로그 라이브러리로 2007년 소스포지에서 1.0 버전을 시작으로 2008년 구글코드로 이전하였고 2012년 1.2까지 릴리즈하고 깃허브로 이전했다.


Maven 프로젝트의 경우 1.16버전까지만 현재 사용할 수 있다.



적용방법

pom파일에 의존 라이브러리 추가후 jdbc url수정 log4j 설정에 추가하고자 하는 log4jdbc logger 설정, log4jdbc.log4j2.properties 파일 추가만 하면 완료되므로 5분이내에 적용이 가능하다.


log4jdbc.log4j2.properties 예시

log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator




Maven pom.xml 설정 JDBC4(JDK 1.6이하일 경우 JDBC3사용) 

<dependency>

  <groupid>org.bgee.log4jdbc-log4j2</groupid>

  <artifactid>log4jdbc-log4j2-jdbc4.1</artifactid>

  <version>1.16</version>

</dependency> 



JDBC URL 설정추가 PostgreSQL 예시

기존 : jdbc:postgres://localhost:5432/dev

변경 : jdbc:log4jdbc:postgres://localhost:5432/dev



log4jdbc.properties 로그설정 파일 추가


log4.xml 설정 추가

loggerdescriptionsince
jdbc.sqlonlyLogs only SQL. SQL executed within a prepared statement is automatically shown with it's bind arguments replaced with the data bound at that position, for greatly increased readability.1.0
jdbc.sqltimingLogs the SQL, post-execution, including timing statistics on how long the SQL took to execute.1.0
jdbc.auditLogs ALL JDBC calls except for ResultSets. This is a very voluminous output, and is not normally needed unless tracking down a specific JDBC problem.1.0
jdbc.resultsetEven more voluminous, because all calls to ResultSet objects are logged.1.0
jdbc.connectionLogs connection open and close events as well as dumping all open connection numbers. This is very useful for hunting down connection leak problems.1.2alpha1


logback.xml 예시



    
    
    
    




프로젝트 홈 : https://code.google.com/p/log4jdbc


JDBC Driver Class

Driver ClassDatabase Type
oracle.jdbc.driver.OracleDriverOlder Oracle Driver
oracle.jdbc.OracleDriverNewer Oracle Driver
com.sybase.jdbc2.jdbc.SybDriverSybase
net.sourceforge.jtds.jdbc.DriverjTDS SQL Server & Sybase driver
com.microsoft.jdbc.sqlserver.SQLServerDriverMicrosoft SQL Server 2000 driver
com.microsoft.sqlserver.jdbc.SQLServerDriverMicrosoft SQL Server 2005 driver
weblogic.jdbc.sqlserver.SQLServerDriverWeblogic SQL Server driver
com.informix.jdbc.IfxDriverInformix
org.apache.derby.jdbc.ClientDriverApache Derby client/server driver, aka the Java DB
org.apache.derby.jdbc.EmbeddedDriverApache Derby embedded driver, aka the Java DB
com.mysql.jdbc.DriverMySQL
org.postgresql.DriverPostgresSQL
org.hsqldb.jdbcDriverHSQLDB pure Java database
org.h2.Driver

H2 pure Java database



jdbc.driver 설정

net.sf.log4jdbc.sql.jdbcapi.DriverSpy



구동시 Log

DEBUG log4jdbc.debug - log4jdbc-logj2 properties initialization...
DEBUG log4jdbc.debug - Using logger: net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
DEBUG log4jdbc.debug - x log4jdbc.debug.stack.prefix is not defined
DEBUG log4jdbc.debug - x log4jdbc.sqltiming.warn.threshold is not defined
DEBUG log4jdbc.debug - x log4jdbc.sqltiming.error.threshold is not defined
DEBUG log4jdbc.debug - x log4jdbc.dump.booleanastruefalse is not defined (using default value false)
DEBUG log4jdbc.debug - x log4jdbc.dump.sql.maxlinelength is not defined (using default of 90)
DEBUG log4jdbc.debug - x log4jdbc.dump.fulldebugstacktrace is not defined (using default value false)
DEBUG log4jdbc.debug - x log4jdbc.statement.warn is not defined (using default value false)
DEBUG log4jdbc.debug - x log4jdbc.dump.sql.select is not defined (using default value true)
DEBUG log4jdbc.debug - x log4jdbc.dump.sql.insert is not defined (using default value true)
DEBUG log4jdbc.debug - x log4jdbc.dump.sql.update is not defined (using default value true)
DEBUG log4jdbc.debug - x log4jdbc.dump.sql.delete is not defined (using default value true)
DEBUG log4jdbc.debug - x log4jdbc.dump.sql.create is not defined (using default value true)
DEBUG log4jdbc.debug - x log4jdbc.dump.sql.addsemicolon is not defined (using default value false)
DEBUG log4jdbc.debug - x log4jdbc.auto.load.popular.drivers is not defined (using default value true)
DEBUG log4jdbc.debug - x log4jdbc.drivers is not defined
DEBUG log4jdbc.debug - x log4jdbc.trim.sql is not defined (using default value true)
DEBUG log4jdbc.debug - x log4jdbc.trim.sql.extrablanklines is not defined (using default value true)
DEBUG log4jdbc.debug - x log4jdbc.suppress.generated.keys.exception is not defined (using default value false)
DEBUG log4jdbc.debug - log4jdbc-logj2 properties initialization done.
DEBUG log4jdbc.debug - DriverSpy intialization...
DEBUG log4jdbc.debug -   FOUND DRIVER org.postgresql.Driver
DEBUG log4jdbc.debug - DriverSpy intialization done.