Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to see the logged sql statements in play2?

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?

like image 233
Freewind Avatar asked Feb 21 '12 03:02

Freewind


3 Answers

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

like image 84
Freewind Avatar answered Nov 03 '22 13:11

Freewind


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>
like image 6
Gabe Brown Avatar answered Nov 03 '22 13:11

Gabe Brown


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

db.default.logStatements=true

logger.com.jolbox.bonecp=DEBUG
like image 4
user3055282 Avatar answered Nov 03 '22 13:11

user3055282