Logging options for Slick
Asked Answered
C

8

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?

Cooney answered 22/1, 2013 at 7:19 Comment(0)
A
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" /> 
Admirable answered 7/3, 2016 at 14:48 Comment(4)
But play-slick uses these paths for the config slick.dbs.default.xxx, so where should I put it?Acrophobia
Updated the answer, hope it helps. I believe Play-Slick is not integrated with jdbcdslog but you can get the queries directly from Slick.Admirable
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). (playframework.com/documentation/2.5.x/…)Acrophobia
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.Admirable
S
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

Sadism answered 22/8, 2013 at 6:9 Comment(3)
With logger.scala.slick.session=DEBUG it only shows select statements but no updates, deletes.Trabue
This doesn't seem to work in all cases, see https://mcmap.net/q/695291/-turn-slick-logging-off (which worked in my case) what may be the reason?Dardanelles
Please note that in Slick 3.* the logger name should be logger.slick and logger.slick.sessionToboggan
D
13

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
Decolorize answered 5/2, 2014 at 5:16 Comment(0)
Z
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" />
Zonnya answered 23/1, 2013 at 6:11 Comment(0)
E
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.

Emulous answered 22/1, 2013 at 7:31 Comment(1)
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.Odonto
J
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>
Jahveh answered 6/8, 2013 at 13:57 Comment(1)
With Slick 3.1.0 (via Play Framework) I found I needed to use <logger name="slick" level="SQL" />Owl
R
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>
Radiosonde answered 10/12, 2015 at 4:57 Comment(1)
Ah, I guess it's because I'm using logback and you're using something else.Radiosonde
F
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

Franco answered 15/6, 2016 at 1:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.