Created
May 26, 2011 15:37
-
-
Save stephanos/993371 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.slf4j._ | |
lazy val log = LoggerFactory.getLogger(loggerName) | |
Session.currentSession.setLogger(logging(_)) | |
def logging(msg: String) { | |
if (log.isDebugEnabled) { | |
val _m = msg.replaceAll("\n", " ").replaceAll(" ", " ").replaceAll(" ", " ") | |
def merge(where: String, params: String) = params.split(",").foldLeft(where)((r, p) => r.replaceFirst("\\?", p)) | |
if (msg.startsWith("Select")) { | |
val selectLog = "Select (.*)? From (.*)? Where (.*)? jdbcParams:\\[(.*)?\\]".r | |
val selectLog(flds, tbl, where, params) = _m | |
val from = tbl.trim.split(" ") | |
val data = merge(where, params).replaceAll(from.last + ".", "") | |
log.debug("select from [" + from.head + "]" + " where " + data) | |
} | |
else if (msg.startsWith("insert")) { | |
val updateLog = "insert into (.*)? \\((.*)?\\) values (.*)? jdbcParams:\\[(.*)?\\]".r | |
val updateLog(tbl, flds, vals, params) = _m | |
val data = merge(flds.replaceAll(",", " = ?,") + " = ?", params) | |
log.debug("insert into [" + tbl + "]" + " values (" + data + ")") | |
} | |
else if (msg.startsWith("update")) { | |
val updateLog = "update (.*)? set (.*)? where (.*)? jdbcParams:\\[(.*)?\\]".r | |
val updateLog(tbl, flds, where, params) = _m | |
val data = merge(flds + "#" + where, params).split("#") | |
log.debug("update [" + tbl + "] where (" + data(1) + ") set (" + data(0) + ")") | |
} | |
//else | |
// log.debug(msg) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment