如何在Play 2.4.0上使用Anorm启用跟踪/调试输出 [英] How to enable trace/debugging output with Anorm on Play 2.4.0
问题描述
在Play 2.4.0中,Anorm移至外部软件包,并且日志记录更改为LogBack( http://logback.qos .ch )
With Play 2.4.0 Anorm got moved to an external package and logging got changed to LogBack (http://logback.qos.ch)
很好,很好,但是没有地方可以很容易地跟踪SQL调用的类/程序包名称.
All well and good but nowhere are the class/package names obvious for tracing SQL calls.
明显"(基于import语句)
The "obvious" (based on the import statements)
<logger name="anorm" level="TRACE" />
<logger name="anorm" level="TRACE" />
什么也没做,我也尝试过
did nothing and I also tried
<logger name="anorm.SQL" level="TRACE" />
<logger name="anorm.SQL" level="TRACE" />
以防万一需要更具体.
just in case it needed to be more specific.
Google搜索已迫在眉睫,所以我很茫然.
Google searches just dead needed so I'm at a loss.
有人吗?
推荐答案
您可以使用
log4jdbc
log4jdbc
我已经在Play 2.4上成功使用了JPA/hibernate和Hikary,设置应该相同,因为这会影响JDBC层.
I have used successfully with JPA/hibernate and Hikary on Play 2.4, the setup should be identically since this influences the JDBC layer.
将库添加到build.sbt:
Add the library to your build.sbt:
"org.bgee.log4jdbc-log4j2" % "log4jdbc-log4j2-jdbc4" % "1.12"
调整配置.添加log4jdbc后,log4jdbc会自动从字符串mysql中检测基础驱动程序.如果您使用的是晦涩的JDBC驱动程序,则可以使用config选项配置它-请参阅下面的文档.
Adjust the config. Add log4jdbc, the log4jdbc automatically detects the underlying driver from the string: mysql. If you are using an obscure JDBC driver, you can configure it using config options - see docs below.
db.default.url="jdbc:log4jdbc:mysql://localhost/......"
db.default.driver=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
我的logback.xml的示例,相关部分:
Example of my logback.xml, relevant part:
<logger name="log4jdbc.log4j2" level="ERROR">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</logger>
<logger name="jdbc.sqlonly" level="INFO" >
<appender-ref ref="DBFILE" />
</logger>
<appender name="DBFILE" class="ch.qos.logback.core.FileAppender">
<file>${application.home}/logs/sql.log</file>
<encoder>
<pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
</encoder>
</appender>
最后是log4jdbc.log4j2.properties(在类路径上的conf目录中创建):
And, finally the log4jdbc.log4j2.properties (create it in the conf directory which is on the class path):
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
更多文档: https://code.google.com/p/log4jdbc-log4j2/
让我知道这是否对您有用
Let me know if this works for you
这篇关于如何在Play 2.4.0上使用Anorm启用跟踪/调试输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!