Where to See the Logged SQL Statements in Play2

Where to see the logged sql statements in play2?

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

Show JPA's SQL-Statements when using Play Framework 2

Try first with the config

db.default.logStatements=true
logger.org.hibernate=DEBUG

Find out which class logs the statements (for example org.hibernate.xxx.StatementLogger).
Change back to INFO for org.hibernate and add a new line for the statement logger package:

logger.org.hibernate=INFO
logger.org.hibernate.xxx=DEBUG

Play 2.4 - Display Ebeans SQL statement in logs

Logging has changed with Play 2.4. Starting from now, to display the SQL statements in the console, simply add the following line to the conf/logback.xml file:

<logger name="org.avaje.ebean.SQL" level="TRACE" />

It should work just fine.

As @Flo354 pointed out in the comments, with Play 2.6 you should use:

<logger name="io.bean" level="TRACE" />

How do you print out filled in Anorm SQL statements in Play framework

You can use the debuging utility from Acolyte (my framework).

import acolyte.jdbc.AcolyteDSL

AcolyteDSL.debuging() { implicit con =>
// debug any JDBC execution within

SQL"SELECT * FROM Test WHERE id = $id"
// Will print the stmt prepared for
}

Play Framework 2.0 and Ebean SQL logging

Sorry to be late to the party, but I use this in development:

db.default.logStatements=true

logger.com.jolbox=DEBUG

Add those two lines to the application.conf and you are good to go.

It outputs all the sql statements. Hope it helps.

Log Oracle SQL statements with Squeryl and Play 2

I just needed to change the oracle.net.ns.level to SEVERE. Logging of oracle.net is only needed if you want to log the network packets being sent to and from the server, which I didn't need in this case.

Where is ? placeholder of sql in play2's anorm

No, currently Anorm uses the Scala symbols for the mapping and you can't use '?'.

This may change in the future, but it is not possible right now.

Ebean Query logging with Play 2.2.3

After play 2.0 the package for ebean has changed. Kindly add following line for play 2.2.3

<logger name="org.avaje.ebean.SQL" level="TRACE"/>

to your application.conf.

for PlayFramework 2.0 and before a

<logger name="com.jolbox.bonecp" level="TRACE"/> 

would do. Hope this helps

Play 2 framework 2.2.4 (ebean): pagination generates mutiple sql queries per one page when call Page .getList()

Play 2.2.4 uses Ebean version 3.2.2, and this version of Ebean uses a "fetch ahead" strategy to get all the pages when you call getPage.

You can change this by setting fetch ahead property to false, like this:

public static Page<Users> page(int pageNum, int pageSize) {
Page<Users> page = find.where()
.findPagingList(pageSize)
.setFetchAhead(false)
.getPage(pageNum);
return page;
}


Related Topics



Leave a reply



Submit