Skip to content

Instantly share code, notes, and snippets.

@johntbush
Created December 19, 2015 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johntbush/baff6ddb4a9fa6d03580 to your computer and use it in GitHub Desktop.
Save johntbush/baff6ddb4a9fa6d03580 to your computer and use it in GitHub Desktop.
import org.slf4j.MDC
import scalikejdbc._
GlobalSettings.taggedQueryCompletionListener = (sql: String, params: Seq[Any], millis: Long, tags: Seq[String]) => {
if (millis > warningThresholdMillis) {
MDC.put("sql", sql)
MDC.put("params", params.mkString("[", ",", "]"))
MDC.put("millis", millis.toString)
MDC.put("error", null)
setExtraProps(tags)
logger.warn(s"completion")
}
}
def setExtraProps(tags: Seq[String]) {
MDC.put("app", appName)
if (tags.size > 0)
MDC.put("server", tags(0))
else
MDC.put("server", null)
if (tags.size > 1)
MDC.put("database", tags(1))
else
MDC.put("database", null)
if (tags.size > 2)
MDC.put("url", tags(2))
else
MDC.put("url", null)
if (tags.size > 3)
MDC.put("user", tags(3))
else
MDC.put("user", null)
if (tags.size > 4)
MDC.put("driver", tags(4))
else
MDC.put("driver", null)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment