Hi all,
I've made a change to the Mapper logging functionality in wip-dcb-sql-log-wrappers. The DB.addLogFunc method has changed to:
addLogFunc( f: (DBLog,Long) => Any)
where DBLog is a new trait (below) and the Long corresponds to the *total* duration of a given DB execution method. DBLog is defined as:
trait DBLog {
... private stuff up here ...
/** Return a list of all of the DBStatementEntry instances in the log buffer */
def statementEntries : List[DBStatementEntry] = ...
/** Return a list of all of the DBMetaEntry instances in the log buffer */
def metaEntries : List[DBMetaEntry] = ...
/** Return all log buffer entries */
def allEntries : List[DBLogEntry] = ...
}
and we have some new event class/traits:
trait DBLogEntry {
def statement : String
def duration : Long
}
object DBLogEntry {
def unapply(obj : Any) = obj match {
case entry : DBLogEntry => Some(entry.statement,entry.duration)
case _ => None
}
}
case class DBStatementEntry(statement : String, duration : Long) extends DBLogEntry
case class DBMetaEntry(statement : String, duration : Long) extends DBLogEntry
Statements are SQL statements, prepared or immediate, and meta entries correspond to things like getMaxRows, getGeneratedKeys, etc. As you can see, each individual statement records its own duration as well, so you can get fine-grained detail on all activity. An example log function in Boot could look like:
DB.addLogFunc {
case (query, time) => {
Log.info("All queries took " + time + "ms: ")
query.allEntries.foreach({ case DBLogEntry(stmt, duration) => Log.info(stmt + " took " + duration + "ms")})
Log.info("End queries")
}
}
And we get output like:
INFO - All queries took 17ms:
INFO - Exec update "INSERT INTO users (lastname,locale,password_pw,password_slt,validated,uniqueid,timezone,firstname,email,superuser,textarea) VALUES ("C","en_US","GzwLqDpmJ6TrECg06bGKvOAQxyc=","1JTAWGSSYLJHXASO",1,"DU0G0RT3IFOA0NHSY5QQQTX42BOIHDGI","US/Mountain","D","
d...@c.com",0,"")" : updated 1 rows took 9ms
INFO - Get generated keys : rs = oracle.jdbc.driver.OracleReturnResultSet@23f9e6e5 took 2ms
INFO - Closed Statement took 0ms
INFO - End queries
Note that this code does introduce a breaking change if you're already using log functions, since the addLogFunc signature has changed. If I can get a review on the code before I merge to master I would appreciate it.
Derek