2012-03-09 71 views

回答

4

你可以很容易通過打開類別DataNucleus.Datastore.Native得到DataNucleus將所有SQL語句的記錄(見http://www.datanucleus.org/products/datanucleus/logging.html

JDO2 InstanceLifecycleListeners將允許您攔截事件,但我不認爲SQL語句將可在那裏...

您還可以查看您的應用程序服務器的SQL分析工具。例如,GlassFish允許您將SQLTraceListener實現附加到連接池。見http://docs.oracle.com/cd/E18930_01/html/821-2418/giyck.html#giygg

0

的Log4j

您可以使用java.util.loggingLog4j通過DataNucleus。我要講述Log4j配置。

log4j.properties

# Define the destination and format of our logging 
log4j.rootCategory=DEBUG, 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 %t %c{1}:%M:%L - %m%n 

# DataNucleus Categories 
log4j.category.DataNucleus=ALL 

最後一行分配水平閾值信息或所有這些都是爲了看到所有DataNucleus將日誌。 DataNucleus使用一系列類別,並將所有消息記錄到這些類別。 See here瞭解更多詳情。你可能需要

  • log4j.category.DataNucleus.Query - 所有的信息與查詢
  • log4j.category.DataNucleus.Datastore - 所有通用的數據存儲信息
  • log4j.category.DataNucleus.JDO - 所有信息一般到JDO

log4j.category.DataNucleus是一切的根DataNucleus日誌類別。

log4j添加到您的CLASSPATH。我用Gradle依賴管理,所以這裏是我的構建腳本:

的build.gradle

configurations { 
    all*.exclude group: "commons-logging", module: "commons-logging" 
} 

dependencies { 
    // Logging 
    compile 'org.slf4j:slf4j-api:1.7.+' 
    runtime 'org.slf4j:slf4j-jdk14:1.7.+' 
    runtime ('log4j:log4j:1.2.17') { 
     exclude group: "com.sun.jdmk", module: "jmxtools" 
     exclude group: "com.sun.jmx", module: "jmxri" 
     exclude group: "javax.mail", module: "mail" 
     exclude group: "javax.jms", module: "jms" 
    }  
} 

要啓動時,您的應用程序設置JVM參數作爲

提供一個Log4j配置文件
-Dlog4j.configuration=file:log4j.properties 

如果您在JavaEE應用程序服務器中運行,可以爲您完成此操作。或者,如果您使用的是Spring WebMVC,請在WEB-INF中放置log4j.properties,並將以下偵聽器添加到您的部署描述符中。

的web.xml

<!-- The definition of the Log4j Configuration --> 
<listener> 
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> 
</listener> 
<context-param> 
    <param-name>log4jConfigLocation</param-name> 
    <param-value>/WEB-INF/log4j.properties</param-value> 
</context-param>