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?
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" />
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 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
logger.slick
and logger.slick.session
–
Toboggan 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
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" />
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.
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>
<logger name="slick" level="SQL" />
–
Owl 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>
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
© 2022 - 2024 — McMap. All rights reserved.
play-slick
uses these paths for the configslick.dbs.default.xxx
, so where should I put it? – Acrophobia