playframework / play-slick

Slick Plugin for Play
Apache License 2.0
804 stars 283 forks source link

Cannot log evolutions #389

Open jdelafon opened 7 years ago

jdelafon commented 7 years ago

With the standard jdbc module in Play, one can log evolutions being applied by adding this to "logback.xml":

  <logger name="play.api.db.evolutions" level="DEBUG" />

Unfortunately it does not work anymore with play-slick. I could not find another logger concerning evolutions in the documentation. I am only running evolutions in tests, on an empty MySQL database - not sure if it matters.

N.B. That one will only log statements after evolutions have already been applied:

<logger name="slick.jdbc.JdbcBackend.statement" level="OFF" />
marcospereira commented 7 years ago

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

Does that works for you?

jdelafon commented 7 years ago

It does not. Is it supposed to? I have this:

logSql=true

<!-- Show SQL (jdbc) -->
<logger name="com.jolbox.bonecp" level="OFF">
  <appender-ref ref="STDOUT" />
</logger>
<logger name="com.zaxxer.hikari" level="OFF">
  <appender-ref ref="STDOUT" />
</logger>
<logger name="org.jdbcdslog.ConnectionLogger" level="OFF" /> 
<logger name="org.jdbcdslog.StatementLogger"  level="OFF" /> 
<logger name="org.jdbcdslog.ResultSetLogger"  level="OFF" /> 

<!-- Slick -->
<logger name="slick.jdbc.JdbcBackend.statement" level="OFF" />
<logger name="slick" level="INFO"/>

<!-- Evolutions -->
<logger name="play.api.db.evolutions" level="DEBUG" />

Setting any of this to DEBUG or INFO will not log evolutions.

iref commented 7 years ago

I think I found root of the problem. Slick evolutions work directly with java.sql.Connection that is retrieved from data source. Because evolution scripts are run on raw connection and don't use Slick session and aren't picked up by slick.jdbc.JdbcBackend.statement. On the other hand, jdbcdslog is instrumented by wrapping datasource to LogSqlDataSource in play-jdbc module. So in this jdbcdslog is not enabled because play-slick does not use play-jdbc. @marcospereira is this correct reasoning or am I way off? :)

@jdelafon As workaround, you can try to enable logging in jdbc driver.

jdelafon commented 7 years ago

@iref Thanks for digging into it. I am not sure what you mean with the workaround, but I already tried the loggers above (like org.jdbcdslog.StatementLogger) and they don't show evolutions either. It is not problematic for me anymore right now, so I can wait for a fix. [Edit closed by mistake]

iref commented 7 years ago

For example, you can add org.postgresql DEBUG logger to log statements to postgresql. This is vendor specific and not every jdbc driver supports it. Play JDBC uses jdbcdslog to solve this for all vendors. So you can use this as alternative until play-slick fixes it.