2012-03-09 105 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>