Skip to content

Commit 22a497e

Browse files
dwickernanalytically
authored andcommitted
fix macro when interpolated argument is Throwable
1 parent 5adb356 commit 22a497e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/main/scala-2/com/typesafe/scalalogging/LoggerMacro.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ private[scalalogging] object LoggerMacro {
295295
private def formatArgs(c: LoggerContext)(args: c.Expr[Any]*) = {
296296
import c.universe._
297297
args.map { arg =>
298-
c.Expr[AnyRef](if (arg.tree.tpe <:< weakTypeOf[AnyRef]) arg.tree else q"$arg.asInstanceOf[_root_.scala.AnyRef]")
298+
c.Expr[AnyRef](if (arg.tree.tpe <:< weakTypeOf[AnyRef]) q"$arg: _root_.scala.AnyRef" else q"$arg.asInstanceOf[_root_.scala.AnyRef]")
299299
}
300300
}
301301
}

src/test/scala/com/typesafe/scalalogging/LoggerSpec.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,13 @@ class LoggerSpec extends AnyWordSpec with Matchers with Varargs with MockitoSuga
451451
logger.error(s"""foo\nbar $arg1""")
452452
verify(underlying).error(s"""foo\nbar {}""", arg1)
453453
}
454+
455+
"call the underlying format method when interpolated argument is a Throwable" in {
456+
val f = fixture(_.isErrorEnabled, isEnabled = true)
457+
import f._
458+
logger.error(s"""foo\nbar $arg7""")
459+
verify(underlying).error(s"""foo\nbar {}""", arg7ref)
460+
}
454461
}
455462

456463
"Logging a message using slf4 interpolator and Any args" should {
@@ -587,6 +594,8 @@ class LoggerSpec extends AnyWordSpec with Matchers with Varargs with MockitoSuga
587594
val arg5ref = arg5.asInstanceOf[AnyRef]
588595
val arg6 = 6L
589596
val arg6ref = arg6.asInstanceOf[AnyRef]
597+
val arg7 = new Throwable
598+
val arg7ref = arg7.asInstanceOf[AnyRef]
590599
val underlying = mock[org.slf4j.Logger]
591600
when(p(underlying)).thenReturn(isEnabled)
592601
val logger = Logger(underlying)

0 commit comments

Comments
 (0)