哪里可以看到play2中记录的sql语句? [英] Where to see the logged sql statements in play2?

查看:29
本文介绍了哪里可以看到play2中记录的sql语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发现application.conf中有这样的配置:

# 如果启用,记录正在执行的 SQL 语句.db.default.logStatements=true

我已启用它,但我找不到任何记录执行的 sql 的日志文件.

我在哪里可以找到它,或者我错过了什么?

解决方案

1.应用程序.conf

确保:

db.default.logStatements=true

这个config其实就是play2中使用的连接池boncp的设置

2.自定义记录器

将自定义记录器配置添加到 conf/logger.xml.

内容可能是:

<预><代码><配置><appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"><编码器><pattern>%-5level - %msg%n</pattern></编码器></appender><logger name="com.jolbox.bonecp" level="DEBUG"><appender-ref ref="STDOUT"/><logger name="play" level="DEBUG"><appender-ref ref="STDOUT"/><logger name="application" level="DEBUG"><appender-ref ref="STDOUT"/></配置>

com.jlbox.bonecp 用于bonecpplayapplication 用于play2.

3.在 application.conf 中禁用记录器设置

application.conf 中注释记录器设置:

# 记录器#~~~~~~# 您还可以通过在 conf 目录中提供 logger.xml 文件来配置 logback (http://logback.qos.ch/).# 根记录器:# logger.root=错误# 框架使用的记录器:# logger.play=INFO# 提供给您的应用程序的记录器:# logger.application=DEBUG

重新开始播放,您将看到所有执行的SQL(包括参数值).

I found there is such a configuration in application.conf:

# If enabled, log SQL statements being executed.
db.default.logStatements=true

I've enabled it, but I can't find any log file which logged executed sqls.

Where can I find it, or do I miss something?

解决方案

1. application.conf

make sure:

db.default.logStatements=true

This config is actually a setting of bonecp which is connection pool used in play2

2. custom logger

Add a custom logger configuration to conf/logger.xml.

The content may be:

<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%-5level - %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="com.jolbox.bonecp" level="DEBUG">
        <appender-ref ref="STDOUT" />
    </logger>

    <logger name="play" level="DEBUG">
        <appender-ref ref="STDOUT" />
    </logger>

    <logger name="application" level="DEBUG">
        <appender-ref ref="STDOUT" />
    </logger>

</configuration>

The com.jlbox.bonecp is for bonecp, and play and application are for play2.

3. disable logger settings in application.conf

Comment the logger settings in application.conf:

# Logger
# ~~~~~
# You can also configure logback (http://logback.qos.ch/), by providing a logger.xml file in the conf directory .

# Root logger:
# logger.root=ERROR

# Logger used by the framework:
# logger.play=INFO

# Logger provided to your application:
# logger.application=DEBUG

Restart play, and you will see all executed SQLs(including parameter values).

这篇关于哪里可以看到play2中记录的sql语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆