log4jdbc-remix安装配置

1、maven安装依赖

<dependency>
  <groupId>org.lazyluke</groupId>
  <artifactId>log4jdbc-remix</artifactId>
  <version>0.2.7</version>
</dependency>

2、spring中的配置:

 

<bean id="dataSourceSpied" class="...">
    <property name="driverClass" value="${datasource.driverClassName}"/>
    <property name="jdbcUrl" value="${datasource.url}"/>
    <property name="user" value="${datasource.username}"/>
    <property name="password" value="${datasource.password}"/>
    ...
  </bean>

  <bean id="dataSource" class="net.sf.log4jdbc.Log4jdbcProxyDataSource">
    <constructor-arg ref="dataSourceSpied" />
  </bean>
也可以格式化一下sql输出,配置如下:

<bean id="dataSource" class="net.sf.log4jdbc.Log4jdbcProxyDataSource">
    <constructor-arg ref="dataSourceSpied" />
    <property name="logFormatter"> 
      <bean class="net.sf.log4jdbc.tools.Log4JdbcCustomFormatter"> 
        <property name="loggingType" value="MULTI_LINE" /> 
        <property name="margin" value="19" /> 
        <property name="sqlPrefix" value="SQL:::" /> 
      </bean> 
    </property> 
  </bean>


3、log4j.properties配置

##-------------log4jdbc 配置方式示例---------------##
#值设置方式 :如果关闭设置为OFF,如果开启设置为ON(默认debug级别)或(设置输出级别,输出器)
log4j.logger.jdbc.sqlonly=OFF
log4j.logger.jdbc.sqltiming=INFO,sql
log4j.logger.jdbc.audit=OFF
log4j.logger.jdbc.resultset=OFF
log4j.logger.jdbc.connection=OFF
log4j.logger.jdbc.resultsettable=INFO,sql

log4j.additivity.jdbc.sqlonly=false
log4j.additivity.jdbc.sqltiming=false
log4j.additivity.jdbc.audidt=false
log4j.additivity.jdbc.resultset=false
log4j.additivity.jdbc.connection=false
log4j.additivity.jdbc.resultsettable=false

! the appender used for the JDBC API layer call logging above, sql only
log4j.appender.sql=org.apache.log4j.FileAppender
log4j.appender.sql.File=D:/logs/sql.log
log4j.appender.sql.Append=false
log4j.appender.sql.layout=org.apache.log4j.PatternLayout
log4j.appender.sql.layout.ConversionPattern= %d{yyyy-MM-dd HH:mm:ss.SSS} %m%n%n
log4j.additivity.sql=false


4、参考文章

log4jdbc-remix官网:https://code.google.com/p/log4jdbc-remix/

http://houfeng0923.iteye.com/blog/1266375

你可能感兴趣的:(log4jdbc-remix安装配置)