官方: [url]https://code.google.com/p/log4jdbc/[/url]
log4jdbc分析sql性能 [url]http://hongliangpan.iteye.com/blog/1088398[/url]
xml配置方法: log4jdbc日志框架介绍 [url]http://blog.sina.com.cn/s/blog_57769b7b0101m1il.html[/url]

[url]http://xiaominghimi.blog.51cto.com/2614927/969781[/url]

[color=red]log4j不能使用1.2.15版本,否则丢失包,浪费时间[/color]

<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.6.1</version>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.16</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.6.1</version>
		</dependency>
		<dependency>
			<groupId>org.lazyluke</groupId>
			<artifactId>log4jdbc-remix</artifactId>
			<version>0.2.7</version>
		</dependency>



启动程序改为:


[color=blue]jdbc.driver=net.sf.log4jdbc.DriverSpy


jdbc.url=jdbc:log4jdbc:sqlserver//localhost:1433;DatabaseName=Test[/color]


在jdbc和sqlserver之间加上log4jdbc,就变成了[color=red][b]jdbc:log4jdbc:sqlserver[/b][/color]


比如mysql就应该写成: [color=red][b]jdbc:log4jdbc:mysql[/b][/color]://localhost:3306/jbpmtest


[color=darkblue]Easy to configure, in most cases all you need to do is change the driver class name to [b]net.sf.log4jdbc.DriverSpy[/b] and prepend "[b]jdbc:log4[/b]" to your existing jdbc url, set up your logging categories and you're ready to go![/color]



[color=red][b]log4j.properties[/b][/color]



log4j.rootLogger=warn, stdout


### direct log messages to stdout ###


log4j.appender.stdout=org.apache.log4j.ConsoleAppender


log4j.appender.stdout.Target=System.out


log4j.appender.stdout.layout=org.apache.log4j.PatternLayout


log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n



# log4jdbc


log4j.logger.jdbc.sqlonly=INFO


log4j.logger.jdbc.sqltiming=INFO


log4j.logger.jdbc.audit=OFF


log4j.logger.jdbc.resultset=OFF


log4j.logger.jdbc.connection=OFF




两种配置参考


[color=red][b]log4j.xml[/b][/color]


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- An example log4j configuration xml file for log4jdbc -->
<!-- Logging levels are:                                  -->
<!-- DEBUG < INFO < WARN < ERROR < FATAL                  -->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  <appender name="stdout-appender" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p %c{1}: %m%n"/>
    </layout>
  </appender>
  <appender name="sql-appender" class="org.apache.log4j.FileAppender">
    <param name="File" value="./logs/sql.log"/>
    <param name="Append" value="false"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="-----> %d{yyyy-MM-dd HH:mm:ss.SSS} <%t> %m%n%n"/>
    </layout>
  </appender>
  <appender name="sql-timing-appender" class="org.apache.log4j.FileAppender">
    <param name="File" value="./logs/sqltiming.log"/>
    <param name="Append" value="false"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="-----> %d{yyyy-MM-dd HH:mm:ss.SSS} %m%n%n"/>
    </layout>
  </appender>
  <appender name="jdbc-appender" class="org.apache.log4j.FileAppender">
    <param name="File" value="./logs/jdbc.log"/>
    <param name="Append" value="false"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %m%n"/>
    </layout>
  </appender>
  <appender name="jdbc-connection" class="org.apache.log4j.FileAppender">
    <param name="File" value="./logs/connection.log"/>
    <param name="Append" value="false"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %m%n"/>
    </layout>
  </appender>
  <!--
       The Following 5 logs can be turned on and off while the server is running
       LIVE in order to trace the SQL and/or all JDBC coming out of the application.
       To turn a log on, set the level value to INFO or DEBUG (to see class name and
       line number information in the log)  The DEBUG setting is much more inefficient
       but the output is much more useful.
       To turn off JDBC logging completely, you must set all 5 logs to a level higher
       than ERROR (FATAL is suggested.)
  -->
  <!-- log SQL (pre-execution) plus exceptions caused by SQL -->
  <logger name="jdbc.sqlonly" additivity="false">
    <level value="debug"/>
    <appender-ref ref="sql-appender"/>
  </logger>
  <!-- log SQL with timing information, post execution -->
  <logger name="jdbc.sqltiming" additivity="false">
    <level value="fatal"/>
    <appender-ref ref="sql-timing-appender"/>
  </logger>
  <!-- only use the two logs below to trace ALL JDBC information,
       NOTE:  This can be very voluminous!  -->
  <!-- log all jdbc calls except ResultSet calls -->
  <logger name="jdbc.audit" additivity="false">
    <level value="fatal"/>
    <appender-ref ref="jdbc-appender"/>
  </logger>
  <!-- log the jdbc ResultSet calls -->
  <logger name="jdbc.resultset" additivity="false">
    <level value="fatal"/>
    <appender-ref ref="jdbc-appender"/>
  </logger>

  <!-- log connection open/close events and dump of all open connection numbers -->
  <logger name="jdbc.connection" additivity="false">
    <level value="fatal"/>
    <appender-ref ref="connection-appender"/>
  </logger>
  <!-- this log is for internal debugging of log4jdbc, itself -->
  <!-- debug logging for log4jdbc itself -->
  <logger name="log4jdbc.debug" additivity="false">
    <level value="debug"/>
    <appender-ref ref="stdout-appender"/>
  </logger>
  <!-- by default, log everything to the console with a level of WARN or higher -->
  <root>
    <level value="warn"/>
    <appender-ref ref="stdout-appender"/>
  </root>
</log4j:configuration>



[color=red][b]log4j.properties[/b][/color]


[color=darkblue]!==============================================================================


! log4j.properties - An example configuration properties file for log4j.


!


! Logging levels are:


! DEBUG < INFO < WARN < ERROR < FATAL


!==============================================================================


! turn on the internal log4j debugging flag so we can see what it is doing


log4j.debug=true


!==============================================================================


! JDBC API layer call logging :


! INFO shows logging, DEBUG also shows where in code the jdbc calls were made,


! setting DEBUG to true might cause minor slow-down in some environments.


! If you experience too much slowness, use INFO instead.


! Log all JDBC calls except for ResultSet calls


log4j.logger.jdbc.audit=INFO,jdbc


log4j.additivity.jdbc.audit=false


! Log only JDBC calls to ResultSet objects


log4j.logger.jdbc.resultset=INFO,jdbc


log4j.additivity.jdbc.resultset=false


! Log only the SQL that is executed.


log4j.logger.jdbc.sqlonly=DEBUG,sql


log4j.additivity.jdbc.sqlonly=false


! Log timing information about the SQL that is executed.


log4j.logger.jdbc.sqltiming=DEBUG,sqltiming


log4j.additivity.jdbc.sqltiming=false


! Log connection open/close events and connection number dump


log4j.logger.jdbc.connection=FATAL,connection


log4j.additivity.jdbc.connection=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=./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


! the appender used for the JDBC API layer call logging above, sql timing


log4j.appender.sqltiming=org.apache.log4j.FileAppender


log4j.appender.sqltiming.File=./logs/sqltiming.log


log4j.appender.sqltiming.Append=false


log4j.appender.sqltiming.layout=org.apache.log4j.PatternLayout


log4j.appender.sqltiming.layout.ConversionPattern=-----> %d{yyyy-MM-dd HH:mm:ss.SSS} %m%n%n


! the appender used for the JDBC API layer call logging above


log4j.appender.jdbc=org.apache.log4j.FileAppender


log4j.appender.jdbc.File=./logs/jdbc.log


log4j.appender.jdbc.Append=false


log4j.appender.jdbc.layout=org.apache.log4j.PatternLayout


log4j.appender.jdbc.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %m%n


! the appender used for the JDBC Connection open and close events


log4j.appender.connection=org.apache.log4j.FileAppender


log4j.appender.connection.File=./logs/connection.log


log4j.appender.connection.Append=false


log4j.appender.connection.layout=org.apache.log4j.PatternLayout


log4j.appender.connection.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %m%n[/color]