Skip to content

Instantly share code, notes, and snippets.

@arturaz
Created June 2, 2017 06:37
Show Gist options
  • Save arturaz/56722e9203050e4f4cc28488e54610b9 to your computer and use it in GitHub Desktop.
Save arturaz/56722e9203050e4f4cc28488e54610b9 to your computer and use it in GitHub Desktop.
// Usage
log.debug(s"Writing batched data to DB (singles: ${data.size}, arrays ${arrayData.size})")
// Implementation
def debug(message: String): Unit = macro LoggerMacro.debugMessage
// Macro
def debugMessage(c: LoggerContext)(message: c.Expr[String]) = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
q"if ($underlying.isDebugEnabled) $underlying.debug($message)"
}
@arturaz
Copy link
Author

arturaz commented Jun 2, 2017

type LoggerContext = Context { type PrefixType = Logger }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment