标签:log4jdbc
1.http://log4jdbc.googlecode.com/files/log4jdbc4-1.2.jar
http://www.slf4j.org/download.html
下载log4jdbc4-1.2.jar,slf4j-api-1.7.5.jar , slf4j-log4j12-1.7.5.jar 三个jar包。
2.修改JDBC配置文件
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="net.sf.log4jdbc.DriverSpy"/>
<property name="url" value="jdbc:log4jdbc:mysql://localhost:3306/atpco"/>
<property name="username" value="${username}"/>
<property name="password" ref="ddns_password" />
</bean>
driverClassName修改为net.sf.log4jdbc.DriverSpy
url在原来的基础上jdbc: 变为jdbc:log4jdbc:(加个前缀‘log4jdbc:’)
3.修改log4j.properties 配置文件
在原来的基础上加上以下代码:
#For jdbc
# Root logger option
log4j.logger.jdbc.audit=INFO, file
log4j.additivity.jdbc.audit=true
log4j.logger.jdbc.sqltiming=INFO, file
log4j.additivity.jdbc.sqltiming=true
log4j.logger.jdbc.connection=INFO, file
log4j.additivity.jdbc.connection=true
log4j.logger.jdbc.resultset=FATAL,file
log4j.additivity.jdbc.resultset=false
log4j.logger.jdbc.sqlonly=FATAL,file
log4j.additivity.jdbc.sqlonly=false
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:/logs/log4jdbc.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=10000
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
标签:log4jdbc
原文地址:http://5618698.blog.51cto.com/5608698/1618770