Logging options for Slick

前端 未结 8 1732
抹茶落季
抹茶落季 2020-12-16 13:33

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 f

相关标签:
8条回答
  • 2020-12-16 13:40

    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

    0 讨论(0)
  • 2020-12-16 13:41

    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" />
    
    0 讨论(0)
  • 2020-12-16 13:41

    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.

    0 讨论(0)
  • 2020-12-16 13:43

    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
    
    0 讨论(0)
  • 2020-12-16 13:55

    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>
    
    0 讨论(0)
  • 2020-12-16 13:57

    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" /> 
    
    0 讨论(0)
提交回复
热议问题