2

我正在使用 grails 2.0.4。即使 sql profiler 客户端正在连接;p6spy 没有记录任何内容。

我怀疑问题出在属性文件上,或者与我的 Config.groovy log4j 设置有冲突。

• spy.properties

module.log=com.p6spy.engine.logging.P6LogFactory

realdriver=oracle.jdbc.driver.OracleDriver

dateformat=HH:mm:ss

deregisterdrivers=false

executionthreshold=

outagedetection=false

outagedetectioninterval=

filter=false

include  =

exclude  =

sqlexpression =

autoflush= true

includecategories=

excludecategories=

stringmatcher=

stacktrace=false

stacktraceclass=

reloadproperties=false

reloadpropertiesinterval=60

useprefix=false

appender=com.p6spy.engine.logging.appender.Log4jLogger

append=true

log4j.appender.SQLPROFILER_CLIENT=org.apache.log4j.net.SocketAppender

log4j.appender.SQLPROFILER_CLIENT.RemoteHost=localhost

log4j.appender.SQLPROFILER_CLIENT.Port=4445

log4j.appender.SQLPROFILER_CLIENT.LocationInfo=true

log4j.logger.p6spy=DEBUG,SQLPROFILER_CLIENT

• 数据源.groovy

dataSource {

    pooled = true

    logSql = true

    //driverClassName = "oracle.jdbc.driver.OracleDriver"

    driverClassName = "com.p6spy.engine.spy.P6SpyDriver" // use this driver to enable p6spy logging

    dialect = 'org.hibernate.dialect.Oracle10gDialect'

}

• Config.Groovy

// log4j configuration

log4j = {

    appenders {

        console name:'stdout', layout:pattern(conversionPattern: '%d{ISO8601} [%c{1}] %p: %m%n')

    }

    info    'grails.app' // Logging warnings and higher for all of the app

    error   'org.codehaus.groovy.grails.web.servlet',  //  controllers
            'org.codehaus.groovy.grails.web.pages', //  GSP
            'org.codehaus.groovy.grails.web.sitemesh', //  layouts
            'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
            'org.codehaus.groovy.grails.web.mapping', // URL mapping
            'org.codehaus.groovy.grails.commons', // core / classloading
            'org.codehaus.groovy.grails.plugins', // plugins
            'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
            'org.springframework',
            'org.hibernate',
            'net.sf.ehcache.hibernate'

    trace    'org.hibernate.type'

}
4

2 回答 2

1

The most likely cause of this problem is that the Oracle JDBC driver is being registered by DriverManager before P6SpyDriver. P6Spy 1.3 requires that P6SpyDriver gets registered before the real driver. This is what allowed it to work without any modifications to the JDBC URL.

There are two potential solutions to this issue.

1) Set 'deregisterdrivers=false' in spy.properties. This will cause the driver configured as the 'realdriver' in spy.properties to be deregistered and reregistered when P6SpyDriver is loaded. This enforces the correct ordering within DriverManager.

2) Set 'useprefix=true' in spy.properties and add the prefix 'p6spy:' to your JDBC URL. Since the JDBC URL is different, the order of registration no longer matters.

Further troubleshooting tips: http://p6spy.github.io/p6spy/1.3/troubleshooting.html

于 2014-03-17T17:08:27.503 回答
0

我遇到了一些问题,P6Spy 没有检测到 H2 的正确驱动程序。最后我选择了log4jdbc。它对其代码进行了更新。P6Spy 已经有一段时间没有更新了,但也许没有必要。我在博客中写了几行关于log4jdbc、grails 和 tomcat7的经验。可能对你有点用!

于 2012-11-29T13:18:04.127 回答