Skip to content

Added the missing when***Enabled() methods in LoggerTakingImplicitImpl #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class LoggerTakingImplicitImpl[A] private[scalalogging] {

def error(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.errorMessageArgsMarker[A]

def whenErrorEnabled(body: Unit)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.errorCode[A]

// Warn

def warn(message: String)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.warnMessage[A]
Expand All @@ -32,6 +34,8 @@ class LoggerTakingImplicitImpl[A] private[scalalogging] {

def warn(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.warnMessageArgsMarker[A]

def whenWarnEnabled(body: Unit)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.warnCode[A]

// Info

def info(message: String)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.infoMessage[A]
Expand All @@ -46,6 +50,8 @@ class LoggerTakingImplicitImpl[A] private[scalalogging] {

def info(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.infoMessageArgsMarker[A]

def whenInfoEnabled(body: Unit)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.infoCode[A]

// Debug

def debug(message: String)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.debugMessage[A]
Expand All @@ -60,6 +66,8 @@ class LoggerTakingImplicitImpl[A] private[scalalogging] {

def debug(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.debugMessageArgsMarker[A]

def whenDebugEnabled(body: Unit)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.debugCode[A]

// Trace

def trace(message: String)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.traceMessage[A]
Expand All @@ -74,4 +82,5 @@ class LoggerTakingImplicitImpl[A] private[scalalogging] {

def trace(marker: Marker, message: String, args: Any*)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.traceMessageArgsMarker[A]

def whenTraceEnabled(body: Unit)(implicit a: A): Unit = macro LoggerTakingImplicitMacro.traceCode[A]
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ private[scalalogging] object LoggerTakingImplicitMacro {
}
}

def errorCode[A](c: LoggerContext[A])(body: c.Expr[Unit])(a: c.Expr[A]): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
val canLogEv = q"${c.prefix}.canLogEv"
q"""if ($underlying.isErrorEnabled) {
$underlying.error($canLogEv.logMessage($body))
$canLogEv.afterLog($a)
}"""
}

// Warn

def warnMessage[A](c: LoggerContext[A])(message: c.Expr[String])(a: c.Expr[A]): c.universe.Tree = {
Expand Down Expand Up @@ -159,6 +169,16 @@ private[scalalogging] object LoggerTakingImplicitMacro {
}
}

def warnCode[A](c: LoggerContext[A])(body: c.Expr[Unit])(a: c.Expr[A]): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
val canLogEv = q"${c.prefix}.canLogEv"
q"""if ($underlying.isWarnEnabled) {
$underlying.warn($canLogEv.logMessage($body))
$canLogEv.afterLog($a)
}"""
}

// Info

def infoMessage[A](c: LoggerContext[A])(message: c.Expr[String])(a: c.Expr[A]): c.universe.Tree = {
Expand Down Expand Up @@ -235,6 +255,16 @@ private[scalalogging] object LoggerTakingImplicitMacro {
}
}

def infoCode[A](c: LoggerContext[A])(body: c.Expr[Unit])(a: c.Expr[A]): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
val canLogEv = q"${c.prefix}.canLogEv"
q"""if ($underlying.isInfoEnabled) {
$underlying.info($canLogEv.logMessage($body))
$canLogEv.afterLog($a)
}"""
}

// Debug

def debugMessage[A](c: LoggerContext[A])(message: c.Expr[String])(a: c.Expr[A]): c.universe.Tree = {
Expand Down Expand Up @@ -311,6 +341,17 @@ private[scalalogging] object LoggerTakingImplicitMacro {
}
}

def debugCode[A](c: LoggerContext[A])(body: c.Expr[Unit])(a: c.Expr[A]): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
val canLogEv = q"${c.prefix}.canLogEv"
q"""if ($underlying.isDebugEnabled) {
$underlying.debug($canLogEv.logMessage($body))
$canLogEv.afterLog($a)
}"""
}


// Trace

def traceMessage[A](c: LoggerContext[A])(message: c.Expr[String])(a: c.Expr[A]): c.universe.Tree = {
Expand Down Expand Up @@ -386,4 +427,14 @@ private[scalalogging] object LoggerTakingImplicitMacro {
}"""
}
}

def traceCode[A](c: LoggerContext[A])(body: c.Expr[Unit])(a: c.Expr[A]): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
val canLogEv = q"${c.prefix}.canLogEv"
q"""if ($underlying.isTraceEnabled) {
$underlying.trace($canLogEv.logMessage($body))
$canLogEv.afterLog($a)
}"""
}
}