File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed
main/scala/com/typesafe/scalalogging
test/scala/com/typesafe/scalalogging Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -239,17 +239,18 @@ private object LoggerMacro {
239239
240240 message.tree match {
241241 case q " scala.StringContext.apply(.. $parts).s(.. $args) " =>
242- val messageFormat = parts.iterator.map({ case Literal (Constant (str : String )) => str })
242+ val format = parts.iterator.map({ case Literal (Constant (str : String )) => str })
243243 // Emulate standard interpolator escaping
244244 .map(StringContext .treatEscapes)
245245 // Escape literal slf4j format anchors if the resulting call will require a format string
246246 .map(str => if (args.nonEmpty) str.replace(" {}" , " \\ {}" ) else str)
247247 .mkString(" {}" )
248248
249- (c.Expr (q " $messageFormat" ), args map { arg =>
250- // Box interpolated AnyVals by explicitly getting the string representation
251- c.Expr [Any ](if (arg.tpe <:< weakTypeOf[AnyVal ]) q " $arg.toString " else arg)
252- })
249+ val formatArgs = args map { arg =>
250+ c.Expr [AnyRef ](if (arg.tpe <:< weakTypeOf[AnyRef ]) arg else q " $arg.asInstanceOf[_root_.scala.AnyRef] " )
251+ }
252+
253+ (c.Expr (q " $format" ), formatArgs)
253254
254255 case _ => (message, Seq .empty)
255256 }
Original file line number Diff line number Diff line change @@ -420,11 +420,18 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
420420
421421 " Logging a message using the standard string interpolator" should {
422422
423- " call the underlying format method with the string representation of AnyVal arguments" in {
423+ " call the underlying format method with boxed versions of value arguments" in {
424424 val f = fixture(_.isErrorEnabled, true )
425425 import f ._
426426 logger.error(s " msg ${1 }" )
427- verify(underlying).error(" msg {}" , 1 .toString)
427+ verify(underlying).error(" msg {}" , 1 .asInstanceOf [AnyRef ])
428+ }
429+
430+ " call the underlying format method with boxed versions of arguments of type Any" in {
431+ val f = fixture(_.isErrorEnabled, true )
432+ import f ._
433+ logger.error(s " msg ${1 .asInstanceOf [Any ]}" )
434+ verify(underlying).error(" msg {}" , 1 .asInstanceOf [AnyRef ])
428435 }
429436
430437 " call the underlying format method escaping literal format anchors" in {
You can’t perform that action at this time.
0 commit comments