1. MAVEN Installation Dependent
<!--Logger - <Dependency> <groupId>Commons-logging</groupId> <Artifactid>Commons-logging</Artifactid> <version>1.2</version> </Dependency> <Dependency> <groupId>Log4j</groupId> <Artifactid>Log4j</Artifactid> <version>${log4j.version}</version> </Dependency> <Dependency> <groupId>Org.slf4j</groupId> <Artifactid>Slf4j-api</Artifactid> <version>${slf4j.version}</version> </Dependency> <Dependency> <groupId>Org.slf4j</groupId> <Artifactid>Slf4j-log4j12</Artifactid> <version>${slf4j.version}</version> </Dependency> <Dependency> <groupId>Org.lazyluke</groupId> <Artifactid>Log4jdbc-remix</Artifactid> <version>0.2.7</version> </Dependency>
2, the Jdbc.properties configuration
Jdbc.driverclassname=net.sf.log4jdbc.DriverSpy
JDBC.URL=JDBC:log4jdbc: Mysql://localhost:3306/xdptest?useunicode=true&characterencoding=utf-8 &autoreconnect=truejdbc.username=rootjdbc.password=root
3. The configuration in spring:
<BeanID= "Datasourcespied"class="..."> < Propertyname= "Driverclass"value= "${jdbc.driverclassname}"/> < Propertyname= "Jdbcurl"value= "${jdbc.url}"/> < Propertyname= "User"value= "${jdbc.username}"/> < Propertyname= "Password"value= "${jdbc.password}"/> ... </Bean>
<!--Note: Other references (such as transaction management configuration), with DataSource instead of datasourcespied <Bean id= "DataSource" class= " Net.sf.log4jdbc.Log4jdbcProxyDataSource "><constructor-arg ref = "Datasourcespied" /> </ Bean >
You can also format the SQL output, which is configured as follows:
<BeanID= "DataSource"class= "Net.sf.log4jdbc.Log4jdbcProxyDataSource"> <Constructor-argref= "Datasourcespied" /> < Propertyname= "Logformatter"> <Beanclass= "Net.sf.log4jdbc.tools.Log4JdbcCustomFormatter"> < Propertyname= "Loggingtype"value= "Multi_line" /> < Propertyname= "margin"value= "+" /> < Propertyname= "Sqlprefix"value= "SQL:::" /> </Bean> </ Property> </Bean>
4, log4j.properties configuration:
# # #-------------LOG4JDBC Configuration Example---------------# # #值设置方式: If off is set to off, if the turn on is set to on (default debug level) or (set output level, output)log4j.logger.jdbc.sqlonly = OFFlog4j.logger.jdbc.sqltiming= info,sqllog4j.logger.jdbc.audit=OFFlog4j.logger.jdbc.resultset=On log4j.logger.jdbc.connection=OFFlog4j.logger.jdbc.resultsettable=Info,sql log4j.additivity.jdbc.sqlonly=falselog4j.additivity.jdbc.sqltiming=falseLog4j.additivity.jdbc.audidt=falseLog4j.additivity.jdbc.resultset=falselog4j.additivity.jdbc.connection=falselog4j.additivity.jdbc.resultsettable=false! The Appender used forthe JDBC API layer call logging above, SQL Onlylog4j.appender.sql=Org.apache.log4j.FileAppenderlog4j.appender.sql.File=d:/logs/Sql.loglog4j.appender.sql.Append=falseLog4j.appender.sql.layout=Org.apache.log4j.PatternLayoutlog4j.appender.sql.layout.ConversionPattern=%d{yyyy-mm-dd HH:mm:ss. SSS}%m%n%Nlog4j.additivity.sql=false
5. Reference Articles
Log4jdbc-remix Official website: https://code.google.com/p/log4jdbc-remix/
http://houfeng0923.iteye.com/blog/1266375
Log4jdbc-remix installation Configuration