How to enable trace/debugging output with Anorm on Play 2.4.0

后端 未结 2 1949
南方客
南方客 2021-01-14 03:52

With Play 2.4.0 Anorm got moved to an external package and logging got changed to LogBack (http://logback.qos.ch)

All well and good but nowhere are the class/package

2条回答
  •  遥遥无期
    2021-01-14 04:43

    You can intercept calls going thru JDBC driver using

    log4jdbc

    I have used successfully with JPA/hibernate and Hikary on Play 2.4, the setup should be identically since this influences the JDBC layer.

    Add the library to your build.sbt:

    "org.bgee.log4jdbc-log4j2" % "log4jdbc-log4j2-jdbc4" % "1.12"
    

    Adjust the config. Add log4jdbc, the log4jdbc automatically detects the underlying driver from the string: mysql. If you are using an obscure JDBC driver, you can configure it using config options - see docs below.

    db.default.url="jdbc:log4jdbc:mysql://localhost/......"
    db.default.driver=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
    

    Example of my logback.xml, relevant part:

    
        
        
    
    
        
    
    
    
        ${application.home}/logs/sql.log
        
            %date - [%level] - from %logger in %thread %n%message%n%xException%n
        
    
    

    And, finally the log4jdbc.log4j2.properties (create it in the conf directory which is on the class path):

    log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
    

    More docs: https://code.google.com/p/log4jdbc-log4j2/

    Let me know if this works for you

提交回复
热议问题