Druid配合log4j监控慢sql

1.在applicationContext.xml 配置Druid增加连接池状态和log4j拦截器


name="proxyFilters">
    <list>
        bean="stat-filter"/>
        bean="log-filter"/>
    list>
配置慢sql执行时间200毫秒,并且开启日志拦截


id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
    
    name="slowSqlMillis" value="200"/>
    name="logSlowSql" value="true"/>
id="log-filter" class="com.alibaba.druid.filter.logging.Log4jFilter">
    name="dataSourceLogEnabled" value="true" />
    name="statementExecutableSqlLogEnable" value="true" />
2.配置log4j.properties

log4j.logger.druid.sql=WARN,druid
log4j.logger.druid.sql.DataSource=WARN,druid
log4j.logger.druid.sql.Connection=WARN,druid
log4j.logger.druid.sql.Statement=WARN,druid

log4j.appender.druid=org.apache.log4j.DailyRollingFileAppender
log4j.appender.druid.layout=org.apache.log4j.PatternLayout
log4j.appender.druid.layout.ConversionPattern= [%d{HH\:mm\:ss}] %c{1} - %m%n
log4j.appender.druid.datePattern='.'yyyy-MM-dd
log4j.appender.druid.Threshold = WARN
log4j.appender.druid.append=true
log4j.appender.druid.File=E:/P/apache-tomcat-7/logs/tmall_ssm/druid-slow-sql.log
3.启动项目即可在指定目录下查看到超过200毫秒sql

你可能感兴趣的:(MySQL)