0

我在 Play Framework (1.2.7) 中使用内存中的 H2 数据库。

为了记录我;TRACE_LEVEL_FILE=3在 Play 中这些参数末尾添加的所有查询application.conf

  1. db.url
  2. %prod.db.url
  3. %debug.db.url

但是什么都没有发生,机器(Mac)上似乎没有创建或更新文件,即使数据库肯定有活动(当我浏览到 H2 的 Web 界面时,我可以看到已经写入了许多记录)。

我错过了什么?如何获取要写入的日志?

4

1 回答 1

2

我不知道,TRACE_LEVEL_FILE但您可以尝试使用p6spy

将以下内容添加到您的dependencies.yml

- p6spy -> p6spy 2.1.2:
    exclude:
      - p6spy -> p6spy-signedjar-test

运行play deps

现在编辑你的“application.conf”如下:

# Comment out the default test URL
#%test.db.url=jdbc:h2:mem:play;MODE=MYSQL;LOCK_MODE=0
# Use the p6spy driver
%test.db.driver=com.p6spy.engine.spy.P6SpyDriver
%test.db.url=jdbc:p6spy:h2:mem:play;MODE=MYSQL;LOCK_MODE=0
# Tell the p6spy driver to use the H2 JPA dialect
%test.jpa.dialect=org.hibernate.dialect.H2Dialect

最后,创建conf/spy.properties并放入以下内容:

appender=com.p6spy.engine.spy.appender.StdoutLogger
realdatasourceclass=org.h2.Driver

就是这样,你可以走了。启动您的应用程序,play test您将看到所有数据库查询都记录到标准输出。

还有很多其他选项可以在spy.properties.

于 2014-11-29T09:50:06.097 回答