Play Framework 2.0 和 Ebean SQL 日志记录 [英] Play Framework 2.0 and Ebean SQL logging
问题描述
我想检查 Ebean 生成了哪些 SQL 语句,以找出在我的 Play 2.0 应用程序中发生某些异常(与 SQL 语法相关)的原因.有没有办法记录 Ebean 在 Play Framework 2.0 中生成的 SQL 语句?
I want to examine what SQL statements are generated by Ebean to find out why certain exceptions (related to SQL syntax) are occurring in my Play 2.0 application. Is there a way to log the SQL statements generated by Ebean in Play Framework 2.0?
在 Play 1.x 中,有一个 jpa.debugSQL
配置选项,如果设置为 true,就会执行此操作.Play 2.0 是否存在类似的 Ebean 设置?关于 Ebean of Play 2.0 的文档页面 仍然有点稀缺.
In Play 1.x, there is a jpa.debugSQL
config option, which if set to true, will do exactly this. Does a similar setting for Ebean exist for Play 2.0? The documentation page about Ebean of Play 2.0 is still a bit scarce.
到目前为止我尝试过的:
我已经在我的控制器和全局对象的 onStart
/onRequest
方法中添加了这些方法调用,但它没有任何效果:
I have added these method calls in my controllers and the onStart
/ onRequest
methods of the Global object, but it doesn't have any effect:
Ebean.getServer(null).getAdminLogging().setLogLevel(LogLevel.SQL);
Ebean.getServer(null).getAdminLogging().setDebugGeneratedSql(Play.isDev());
我已经修改了 application.conf
中的日志级别,但它也没有帮助(即使日志级别为 TRACE
).
I have modified the log levels from application.conf
, but it didn't help either (even with log level TRACE
).
推荐答案
很抱歉来晚了,但我在开发中使用了这个:
Sorry to be late to the party, but I use this in development:
db.default.logStatements=true
logger.com.jolbox=DEBUG
将这两行添加到 application.conf 中,您就可以开始了.
Add those two lines to the application.conf and you are good to go.
它输出所有的sql语句.希望有帮助.
It outputs all the sql statements. Hope it helps.
这篇关于Play Framework 2.0 和 Ebean SQL 日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!