在play2中哪里可以看到记录的sql语句?

发布于 2025-01-08 06:01:21 字数 215 浏览 4 评论 0原文

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

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

我启用了它,但我找不到任何记录执行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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

时光沙漏 2025-01-15 06:01:21

1. application.conf

确保:

db.default.logStatements=true

此配置实际上是在 play2 中使用的连接池 Boncp 的设置

2. 自定义记录器

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

内容可能是:

<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>

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

3.禁用application.conf中的logger设置

注释application.conf中的logger设置:

# 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

重新启动游戏,您将看到所有执行的SQL(包括参数值)。

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).

鲜血染红嫁衣 2025-01-15 06:01:21

据我所知,这在 Play 2.4.2 中不再有效。默认连接池引擎已更改为 HikariCP。

将其添加到您的 application.conf 并按照以下说明进行操作。事情应该有效:

Application.conf

db.default.pool = "bonecp"
db.default.bonecp.logStatements=true

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

<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>

This no longer works in Play 2.4.2 from what I can tell. The default connection pool engine was changed over to HikariCP.

Add this to your application.conf and follow the directions below. Things should work:

Application.conf

db.default.pool = "bonecp"
db.default.bonecp.logStatements=true

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

<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>
合约呢 2025-01-15 06:01:21

只需将以下内容添加到 application.conf (适用于我的 play 2.2.1)

db.default.logStatements=true

logger.com.jolbox.bonecp=DEBUG

Just add the following to application.conf (works for me in play 2.2.1)

db.default.logStatements=true

logger.com.jolbox.bonecp=DEBUG
书信已泛黄 2025-01-15 06:01:21

对于 HikariCP(即从 Play 2.4 开始),请参阅 https://github.com/brettwooldridge /HikariCP/wiki/JDBC-日志记录

HikariCP 此时本身并不包含 JDBC 日志记录。这是一个有意识的决定,而不是疏忽或未开发的未来路线图项目。几乎所有主要数据库都有能够自行记录日志的 JDBC 驱动程序。对于那些不这样做的人,log4jdbc-log4j2 是一个不错的选择。

此 wiki 页面记录了如何为常见数据库以及 log4jdbc-log4j2 启用日志记录。

对于 log4jdbc-log4j2:将 "org.bgee.log4jdbc-log4j2" % "log4jdbc-log4j2-jdbc4.1" % "1.16" 添加到 libraryDependencies 中;配置说明位于 https://code.google.com/archive/p/log4jdbc -log4j2/

For HikariCP (i.e. starting with Play 2.4), see https://github.com/brettwooldridge/HikariCP/wiki/JDBC-Logging:

HikariCP does not inherently include JDBC logging at this time. This is a conscious decision, not an oversight or undeveloped future roadmap item. Nearly all major database have a JDBC driver capable of logging on its own. For those that do not, log4jdbc-log4j2 is a good option.

This wiki page documents how to enable logging for common databases, as well as log4jdbc-log4j2.

For log4jdbc-log4j2: add "org.bgee.log4jdbc-log4j2" % "log4jdbc-log4j2-jdbc4.1" % "1.16" to libraryDependencies; configuration is described at https://code.google.com/archive/p/log4jdbc-log4j2/.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文