ANNOUNCE: New functionality for Mapper logging with breaking changes

24 views
Skip to first unread message

Derek Chen-Becker

unread,
Sep 14, 2009, 2:01:49 PM9/14/09
to liftweb
Hi all,
    I've made a change to the Mapper logging functionality. 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.

Vassil

unread,
Sep 20, 2009, 1:35:27 AM9/20/09
to Lift
Hello,

Shouldn't S.logQuery and S.queryLog be updated as well or deprecated
if they're not going to be used the way they were as parameters to
DB.addLogFun?

Thanks,
Vassil

Derek Chen-Becker

unread,
Sep 25, 2009, 5:50:44 PM9/25/09
to lif...@googlegroups.com
I would vote in favor of deprecation/removal. Vote?
Reply all
Reply to author
Forward
0 new messages