17

I'm createing a Play 2.1 app, in which I have decided to use Slick for database interaction.
However I can't find documentation about how to configure/enable logging for Slick.
Anyone knows this?

8 Answers8

17

For PlayFramework 2.5.0 without Slick

Add to all your database configurations

db.default.logSql=true

Add to your logback.xml file:

<logger name="logger.org.jdbcdslog.StatementLogger"  level="INFO" /> 

All the statements will be logged.

Reference:

https://www.playframework.com/documentation/2.5.x/ScalaDatabase#How-to-configure-SQL-log-statement

For play with Slick 3.0, just use

<logger name="slick.jdbc.JdbcBackend.statement"  level="DEBUG" /> 
JulienD
  • 7,102
  • 9
  • 50
  • 84
Jonas Anso
  • 2,057
  • 14
  • 13
  • But `play-slick` uses these paths for the config `slick.dbs.default.xxx`, so where should I put it? – Gman Apr 05 '16 at 13:11
  • Updated the answer, hope it helps. I believe Play-Slick is not integrated with jdbcdslog but you can get the queries directly from Slick. – Jonas Anso Apr 05 '16 at 13:36
  • 1
    Thank you very much! Interestingly (and that's why I was confused) in the "What's New in Play 2.5" it says `Play now has an easy way to log SQL statements, built on jdbcdslog , that works across all JDBC databases, connection pool implementations and persistence frameworks (Anorm, Ebean, JPA, Slick, etc).` (https://www.playframework.com/documentation/2.5.x/Highlights25#logging-sql-statements) – Gman Apr 06 '16 at 13:15
  • 2
    I could be wrong but reading the play framework code I can't see Slick integrated with jdbcdslog. For sure it does not read the config for logSql. Maybe an issue should be opened. – Jonas Anso Apr 06 '16 at 20:32
16

Slick doesn't do much of any logging above DEBUG level. In application.conf if you add the line:

logger.scala.slick=DEBUG

you're going to get deluged with information from the query compiler.

You're probably just interested in the session information (Connection pool management, query strings, etc). In which case, just add

logger.scala.slick.session=DEBUG

to your Play application's application.conf

moatra
  • 565
  • 1
  • 4
  • 10
  • With logger.scala.slick.session=DEBUG it only shows select statements but no updates, deletes. – Tvaroh Nov 20 '13 at 13:27
  • This doesn't seem to work in all cases, see http://stackoverflow.com/questions/23087858/turn-slick-logging-off (which worked in my case) what may be the reason? – User Jun 19 '15 at 19:55
  • 7
    Please note that in Slick 3.* the logger name should be `logger.slick` and `logger.slick.session` – s4nk Jul 07 '16 at 18:54
12

To print only select statements, in play-2.2.1 with slick 2.0.0, in application.conf have:

logger.scala.slick.jdbc.JdbcBackend.statement=DEBUG
dboldureanu
  • 551
  • 5
  • 13
6

I'm not using Play at the moment, but configure it as you would use logback. This is a nice description for setting up Play logging.

One option is to add

logger.scala.slick=INFO 

to application.conf, as per Play manual. The other, if you have a custom logback.xml, is to add there the following line:

   <logger name="scala.slick" level="INFO" />
Yar
  • 629
  • 6
  • 17
Jack
  • 16,506
  • 19
  • 100
  • 167
4

Slick seems to use slf4j for its logging. So you might want to add a dependency on something like slf4j-simple to your project and set the desired log level for the Slick classes.

  • 2
    And that would mean, for a working example, adding the slf4j-simple-[1.7.5].jar into classpath and -Dorg.slf4j.simpleLogger.defaultLogLevel=trace to the command line. – ArtemGr Dec 25 '13 at 15:34
4

I've tried to integrate the logback.xml with the Slick logger but it doesn't work.

Modifing logger.xml (get it the latest version from GitHub based on your version) and adding the slick logger, instead, works.

<configuration>    
  <conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
     <file>${application.home}/logs/application.log</file>
     <encoder>
       <pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
     </encoder>
   </appender>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%coloredLevel %logger{15} - %message%n%xException{5}</pattern>
    </encoder>
  </appender>

  <logger name="play" level="INFO" />
  <logger name="application" level="DEBUG" />

  <!-- Off these ones as they are annoying, and anyway we manage configuration ourself -->
  <logger name="com.avaje.ebean.config.PropertyMapLoader" level="OFF" />
  <logger name="com.avaje.ebeaninternal.server.core.XmlConfigLoader" level="OFF" />
  <logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread" level="OFF" />
  <logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />
  <logger name="scala.slick" level="SQL" />

  <root level="ERROR">
    <appender-ref ref="STDOUT" />
    <appender-ref ref="FILE" />
  </root>

</configuration>
Lord of the Goo
  • 1,214
  • 15
  • 31
1

For slick 3.1.0, paste this in logback.xml in your resources directory:

<?xml version="1.0" encoding="UTF-8"?>

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="application" level="DEBUG"/>
    <logger name="com.zaxxer.hikari" level="INFO"/>
    <logger name="slick" level="INFO"/>

    <root level="DEBUG">
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>
veegee
  • 359
  • 5
  • 5
0

In my case I had to add <logger name="slick" level="INFO"/> to my log4j2.xml file. I'm using Slick 3.0.3 with Spray 1.3.3 and Log4j 2.1

Taro
  • 1,432
  • 1
  • 16
  • 15