Skip to content
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

Added support for any type of logger message in LoggerImpl #331

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
60 changes: 30 additions & 30 deletions src/main/scala-2/com/typesafe/scalalogging/LoggerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,81 +5,81 @@ class LoggerImpl {

// Error

def error(message: String): Unit = macro LoggerMacro.errorMessage
def error(message: AnyVal): Unit = macro LoggerMacro.errorMessage

def error(message: String, cause: Throwable): Unit = macro LoggerMacro.errorMessageCause
def error(message: AnyVal, cause: Throwable): Unit = macro LoggerMacro.errorMessageCause

def error(message: String, args: Any*): Unit = macro LoggerMacro.errorMessageArgs
def error(message: AnyVal, args: Any*): Unit = macro LoggerMacro.errorMessageArgs

def error(marker: Marker, message: String): Unit = macro LoggerMacro.errorMessageMarker
def error(marker: Marker, message: AnyVal): Unit = macro LoggerMacro.errorMessageMarker

def error(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerMacro.errorMessageCauseMarker
def error(marker: Marker, message: AnyVal, cause: Throwable): Unit = macro LoggerMacro.errorMessageCauseMarker

def error(marker: Marker, message: String, args: Any*): Unit = macro LoggerMacro.errorMessageArgsMarker
def error(marker: Marker, message: AnyVal, args: Any*): Unit = macro LoggerMacro.errorMessageArgsMarker

def whenErrorEnabled(body: Unit): Unit = macro LoggerMacro.errorCode

// Warn

def warn(message: String): Unit = macro LoggerMacro.warnMessage
def warn(message: AnyVal): Unit = macro LoggerMacro.warnMessage

def warn(message: String, cause: Throwable): Unit = macro LoggerMacro.warnMessageCause
def warn(message: AnyVal, cause: Throwable): Unit = macro LoggerMacro.warnMessageCause

def warn(message: String, args: Any*): Unit = macro LoggerMacro.warnMessageArgs
def warn(message: AnyVal, args: Any*): Unit = macro LoggerMacro.warnMessageArgs

def warn(marker: Marker, message: String): Unit = macro LoggerMacro.warnMessageMarker
def warn(marker: Marker, message: AnyVal): Unit = macro LoggerMacro.warnMessageMarker

def warn(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerMacro.warnMessageCauseMarker
def warn(marker: Marker, message: AnyVal, cause: Throwable): Unit = macro LoggerMacro.warnMessageCauseMarker

def warn(marker: Marker, message: String, args: Any*): Unit = macro LoggerMacro.warnMessageArgsMarker
def warn(marker: Marker, message: AnyVal, args: Any*): Unit = macro LoggerMacro.warnMessageArgsMarker

def whenWarnEnabled(body: Unit): Unit = macro LoggerMacro.warnCode

// Info

def info(message: String): Unit = macro LoggerMacro.infoMessage
def info(message: AnyVal): Unit = macro LoggerMacro.infoMessage

def info(message: String, cause: Throwable): Unit = macro LoggerMacro.infoMessageCause
def info(message: AnyVal, cause: Throwable): Unit = macro LoggerMacro.infoMessageCause

def info(message: String, args: Any*): Unit = macro LoggerMacro.infoMessageArgs
def info(message: AnyVal, args: Any*): Unit = macro LoggerMacro.infoMessageArgs

def info(marker: Marker, message: String): Unit = macro LoggerMacro.infoMessageMarker
def info(marker: Marker, message: AnyVal): Unit = macro LoggerMacro.infoMessageMarker

def info(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerMacro.infoMessageCauseMarker
def info(marker: Marker, message: AnyVal, cause: Throwable): Unit = macro LoggerMacro.infoMessageCauseMarker

def info(marker: Marker, message: String, args: Any*): Unit = macro LoggerMacro.infoMessageArgsMarker
def info(marker: Marker, message: AnyVal, args: Any*): Unit = macro LoggerMacro.infoMessageArgsMarker

def whenInfoEnabled(body: Unit): Unit = macro LoggerMacro.infoCode

// Debug

def debug(message: String): Unit = macro LoggerMacro.debugMessage
def debug(message: AnyVal): Unit = macro LoggerMacro.debugMessage

def debug(message: String, cause: Throwable): Unit = macro LoggerMacro.debugMessageCause
def debug(message: AnyVal, cause: Throwable): Unit = macro LoggerMacro.debugMessageCause

def debug(message: String, args: Any*): Unit = macro LoggerMacro.debugMessageArgs
def debug(message: AnyVal, args: Any*): Unit = macro LoggerMacro.debugMessageArgs

def debug(marker: Marker, message: String): Unit = macro LoggerMacro.debugMessageMarker
def debug(marker: Marker, message: AnyVal): Unit = macro LoggerMacro.debugMessageMarker

def debug(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerMacro.debugMessageCauseMarker
def debug(marker: Marker, message: AnyVal, cause: Throwable): Unit = macro LoggerMacro.debugMessageCauseMarker

def debug(marker: Marker, message: String, args: Any*): Unit = macro LoggerMacro.debugMessageArgsMarker
def debug(marker: Marker, message: AnyVal, args: Any*): Unit = macro LoggerMacro.debugMessageArgsMarker

def whenDebugEnabled(body: Unit): Unit = macro LoggerMacro.debugCode

// Trace

def trace(message: String): Unit = macro LoggerMacro.traceMessage
def trace(message: AnyVal): Unit = macro LoggerMacro.traceMessage

def trace(message: String, cause: Throwable): Unit = macro LoggerMacro.traceMessageCause
def trace(message: AnyVal, cause: Throwable): Unit = macro LoggerMacro.traceMessageCause

def trace(message: String, args: Any*): Unit = macro LoggerMacro.traceMessageArgs
def trace(message: AnyVal, args: Any*): Unit = macro LoggerMacro.traceMessageArgs

def trace(marker: Marker, message: String): Unit = macro LoggerMacro.traceMessageMarker
def trace(marker: Marker, message: AnyVal): Unit = macro LoggerMacro.traceMessageMarker

def trace(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerMacro.traceMessageCauseMarker
def trace(marker: Marker, message: AnyVal, cause: Throwable): Unit = macro LoggerMacro.traceMessageCauseMarker

def trace(marker: Marker, message: String, args: Any*): Unit = macro LoggerMacro.traceMessageArgsMarker
def trace(marker: Marker, message: AnyVal, args: Any*): Unit = macro LoggerMacro.traceMessageArgsMarker

def whenTraceEnabled(body: Unit): Unit = macro LoggerMacro.traceCode
}
62 changes: 31 additions & 31 deletions src/main/scala-2/com/typesafe/scalalogging/LoggerMacro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ private[scalalogging] object LoggerMacro {

// Error

def errorMessage(c: LoggerContext)(message: c.Expr[String]): c.universe.Tree = {
def errorMessage(c: LoggerContext)(message: c.Expr[AnyVal]): c.universe.Tree = {
val (messageFormat, args) = deconstructInterpolatedMessage(c)(message)
errorMessageArgs(c)(messageFormat, args: _*)
}

def errorMessageCause(c: LoggerContext)(message: c.Expr[String], cause: c.Expr[Throwable]): c.universe.Tree = {
def errorMessageCause(c: LoggerContext)(message: c.Expr[AnyVal], cause: c.Expr[Throwable]): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
q"if ($underlying.isErrorEnabled) $underlying.error($message, $cause)"
}

def errorMessageArgs(c: LoggerContext)(message: c.Expr[String], args: c.Expr[Any]*): c.universe.Tree = {
def errorMessageArgs(c: LoggerContext)(message: c.Expr[AnyVal], args: c.Expr[Any]*): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
val anyRefArgs = formatArgs(c)(args: _*)
Expand All @@ -30,18 +30,18 @@ private[scalalogging] object LoggerMacro {
q"if ($underlying.isErrorEnabled) $underlying.error($message, ..$anyRefArgs)"
}

def errorMessageMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[String]): c.universe.Tree = {
def errorMessageMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[AnyVal]): c.universe.Tree = {
val (messageFormat, args) = deconstructInterpolatedMessage(c)(message)
errorMessageArgsMarker(c)(marker, messageFormat, args: _*)
}

def errorMessageCauseMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[String], cause: c.Expr[Throwable]): c.universe.Tree = {
def errorMessageCauseMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[AnyVal], cause: c.Expr[Throwable]): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
q"if ($underlying.isErrorEnabled($marker)) $underlying.error($marker, $message, $cause)"
}

def errorMessageArgsMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[String], args: c.Expr[Any]*): c.universe.Tree = {
def errorMessageArgsMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[AnyVal], args: c.Expr[Any]*): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
val anyRefArgs = formatArgs(c)(args: _*)
Expand All @@ -59,18 +59,18 @@ private[scalalogging] object LoggerMacro {

// Warn

def warnMessage(c: LoggerContext)(message: c.Expr[String]): c.universe.Tree = {
def warnMessage(c: LoggerContext)(message: c.Expr[AnyVal]): c.universe.Tree = {
val (messageFormat, args) = deconstructInterpolatedMessage(c)(message)
warnMessageArgs(c)(messageFormat, args: _*)
}

def warnMessageCause(c: LoggerContext)(message: c.Expr[String], cause: c.Expr[Throwable]): c.universe.Tree = {
def warnMessageCause(c: LoggerContext)(message: c.Expr[AnyVal], cause: c.Expr[Throwable]): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
q"if ($underlying.isWarnEnabled) $underlying.warn($message, $cause)"
}

def warnMessageArgs(c: LoggerContext)(message: c.Expr[String], args: c.Expr[Any]*): c.universe.Tree = {
def warnMessageArgs(c: LoggerContext)(message: c.Expr[AnyVal], args: c.Expr[Any]*): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
val anyRefArgs = formatArgs(c)(args: _*)
Expand All @@ -80,18 +80,18 @@ private[scalalogging] object LoggerMacro {
q"if ($underlying.isWarnEnabled) $underlying.warn($message, ..$anyRefArgs)"
}

def warnMessageMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[String]): c.universe.Tree = {
def warnMessageMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[AnyVal]): c.universe.Tree = {
val (messageFormat, args) = deconstructInterpolatedMessage(c)(message)
warnMessageArgsMarker(c)(marker, messageFormat, args: _*)
}

def warnMessageCauseMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[String], cause: c.Expr[Throwable]): c.universe.Tree = {
def warnMessageCauseMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[AnyVal], cause: c.Expr[Throwable]): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
q"if ($underlying.isWarnEnabled($marker)) $underlying.warn($marker, $message, $cause)"
}

def warnMessageArgsMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[String], args: c.Expr[Any]*): c.universe.Tree = {
def warnMessageArgsMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[AnyVal], args: c.Expr[Any]*): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
val anyRefArgs = formatArgs(c)(args: _*)
Expand All @@ -109,18 +109,18 @@ private[scalalogging] object LoggerMacro {

// Info

def infoMessage(c: LoggerContext)(message: c.Expr[String]): c.universe.Tree = {
def infoMessage(c: LoggerContext)(message: c.Expr[AnyVal]): c.universe.Tree = {
val (messageFormat, args) = deconstructInterpolatedMessage(c)(message)
infoMessageArgs(c)(messageFormat, args: _*)
}

def infoMessageCause(c: LoggerContext)(message: c.Expr[String], cause: c.Expr[Throwable]): c.universe.Tree = {
def infoMessageCause(c: LoggerContext)(message: c.Expr[AnyVal], cause: c.Expr[Throwable]): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
q"if ($underlying.isInfoEnabled) $underlying.info($message, $cause)"
}

def infoMessageArgs(c: LoggerContext)(message: c.Expr[String], args: c.Expr[Any]*): c.universe.Tree = {
def infoMessageArgs(c: LoggerContext)(message: c.Expr[AnyVal], args: c.Expr[Any]*): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
val anyRefArgs = formatArgs(c)(args: _*)
Expand All @@ -130,18 +130,18 @@ private[scalalogging] object LoggerMacro {
q"if ($underlying.isInfoEnabled) $underlying.info($message, ..$anyRefArgs)"
}

def infoMessageMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[String]): c.universe.Tree = {
def infoMessageMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[AnyVal]): c.universe.Tree = {
val (messageFormat, args) = deconstructInterpolatedMessage(c)(message)
infoMessageArgsMarker(c)(marker, messageFormat, args: _*)
}

def infoMessageCauseMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[String], cause: c.Expr[Throwable]): c.universe.Tree = {
def infoMessageCauseMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[AnyVal], cause: c.Expr[Throwable]): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
q"if ($underlying.isInfoEnabled($marker)) $underlying.info($marker, $message, $cause)"
}

def infoMessageArgsMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[String], args: c.Expr[Any]*): c.universe.Tree = {
def infoMessageArgsMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[AnyVal], args: c.Expr[Any]*): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
val anyRefArgs = formatArgs(c)(args: _*)
Expand All @@ -159,18 +159,18 @@ private[scalalogging] object LoggerMacro {

// Debug

def debugMessage(c: LoggerContext)(message: c.Expr[String]): c.universe.Tree = {
def debugMessage(c: LoggerContext)(message: c.Expr[AnyVal]): c.universe.Tree = {
val (messageFormat, args) = deconstructInterpolatedMessage(c)(message)
debugMessageArgs(c)(messageFormat, args: _*)
}

def debugMessageCause(c: LoggerContext)(message: c.Expr[String], cause: c.Expr[Throwable]): c.universe.Tree = {
def debugMessageCause(c: LoggerContext)(message: c.Expr[AnyVal], cause: c.Expr[Throwable]): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
q"if ($underlying.isDebugEnabled) $underlying.debug($message, $cause)"
}

def debugMessageArgs(c: LoggerContext)(message: c.Expr[String], args: c.Expr[Any]*): c.universe.Tree = {
def debugMessageArgs(c: LoggerContext)(message: c.Expr[AnyVal], args: c.Expr[Any]*): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
val anyRefArgs = formatArgs(c)(args: _*)
Expand All @@ -180,18 +180,18 @@ private[scalalogging] object LoggerMacro {
q"if ($underlying.isDebugEnabled) $underlying.debug($message, ..$anyRefArgs)"
}

def debugMessageMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[String]): c.universe.Tree = {
def debugMessageMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[AnyVal]): c.universe.Tree = {
val (messageFormat, args) = deconstructInterpolatedMessage(c)(message)
debugMessageArgsMarker(c)(marker, messageFormat, args: _*)
}

def debugMessageCauseMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[String], cause: c.Expr[Throwable]): c.universe.Tree = {
def debugMessageCauseMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[AnyVal], cause: c.Expr[Throwable]): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
q"if ($underlying.isDebugEnabled($marker)) $underlying.debug($marker, $message, $cause)"
}

def debugMessageArgsMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[String], args: c.Expr[Any]*): c.universe.Tree = {
def debugMessageArgsMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[AnyVal], args: c.Expr[Any]*): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
val anyRefArgs = formatArgs(c)(args: _*)
Expand All @@ -209,18 +209,18 @@ private[scalalogging] object LoggerMacro {

// Trace

def traceMessage(c: LoggerContext)(message: c.Expr[String]): c.universe.Tree = {
def traceMessage(c: LoggerContext)(message: c.Expr[AnyVal]): c.universe.Tree = {
val (messageFormat, args) = deconstructInterpolatedMessage(c)(message)
traceMessageArgs(c)(messageFormat, args: _*)
}

def traceMessageCause(c: LoggerContext)(message: c.Expr[String], cause: c.Expr[Throwable]): c.universe.Tree = {
def traceMessageCause(c: LoggerContext)(message: c.Expr[AnyVal], cause: c.Expr[Throwable]): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
q"if ($underlying.isTraceEnabled) $underlying.trace($message, $cause)"
}

def traceMessageArgs(c: LoggerContext)(message: c.Expr[String], args: c.Expr[Any]*): c.universe.Tree = {
def traceMessageArgs(c: LoggerContext)(message: c.Expr[AnyVal], args: c.Expr[Any]*): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
val anyRefArgs = formatArgs(c)(args: _*)
Expand All @@ -230,18 +230,18 @@ private[scalalogging] object LoggerMacro {
q"if ($underlying.isTraceEnabled) $underlying.trace($message, ..$anyRefArgs)"
}

def traceMessageMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[String]): c.universe.Tree = {
def traceMessageMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[AnyVal]): c.universe.Tree = {
val (messageFormat, args) = deconstructInterpolatedMessage(c)(message)
traceMessageArgsMarker(c)(marker, messageFormat, args: _*)
}

def traceMessageCauseMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[String], cause: c.Expr[Throwable]): c.universe.Tree = {
def traceMessageCauseMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[AnyVal], cause: c.Expr[Throwable]): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
q"if ($underlying.isTraceEnabled($marker)) $underlying.trace($marker, $message, $cause)"
}

def traceMessageArgsMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[String], args: c.Expr[Any]*): c.universe.Tree = {
def traceMessageArgsMarker(c: LoggerContext)(marker: c.Expr[Marker], message: c.Expr[AnyVal], args: c.Expr[Any]*): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
val anyRefArgs = formatArgs(c)(args: _*)
Expand All @@ -258,7 +258,7 @@ private[scalalogging] object LoggerMacro {
}

/** Checks whether `message` is an interpolated string and transforms it into SLF4J string interpolation. */
private def deconstructInterpolatedMessage(c: LoggerContext)(message: c.Expr[String]) = {
private def deconstructInterpolatedMessage(c: LoggerContext)(message: c.Expr[AnyVal]) = {
val u: c.universe.type = c.universe
// Eww; gross! In 2.13, the `s` interpolator on StringContext became a macro, so we have to look at the pre-macro
// expansion tree to recover what the user wrote...
Expand Down