Logging options for Slick

2020-02-10 12:31发布

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条回答
来,给爷笑一个
2楼-- · 2020-02-10 13:08

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

查看更多
祖国的老花朵
3楼-- · 2020-02-10 13:08

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.

查看更多
来,给爷笑一个
4楼-- · 2020-02-10 13:12

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>
查看更多
Explosion°爆炸
5楼-- · 2020-02-10 13:12

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

查看更多
迷人小祖宗
6楼-- · 2020-02-10 13:14

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" />
查看更多
我只想做你的唯一
7楼-- · 2020-02-10 13:15

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>
查看更多
登录 后发表回答