File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
main/scala/com/typesafe/scalalogging
test/scala/com/typesafe/scalalogging Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -239,8 +239,8 @@ private object LoggerMacro {
239239
240240 message.tree match {
241241 case q " scala.StringContext.apply(.. $parts).s(.. $args) " =>
242- // Escape slf4j format anchors
243- val messageFormat = parts.map({ case Literal (Constant (s : String )) => s .replace(" {}" , " \\ {}" ) }).mkString(" {}" )
242+ // Emulate standard interpolator escaping and escape literal slf4j format anchors
243+ val messageFormat = parts.map({ case Literal (Constant (s : String )) => StringContext .treatEscapes(s) .replace(" {}" , " \\ {}" ) }).mkString(" {}" )
244244 (c.Expr (q " $messageFormat" ), args map { arg =>
245245 // Box interpolated AnyVals by explicitly getting the string representation
246246 c.Expr [Any ](if (arg.tpe <:< weakTypeOf[AnyVal ]) q " $arg.toString " else arg)
Original file line number Diff line number Diff line change @@ -74,6 +74,19 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
7474 logger.error(s " foo {} bar $arg1" )
7575 verify(underlying).error(" foo \\ {} bar {}" , arg1)
7676 }
77+
78+ " call the underlying logger's error method when the interpolated string contains escape sequences" in {
79+ val f = fixture(_.isErrorEnabled, true )
80+ import f ._
81+ logger.error(s " foo \n bar $arg1" )
82+ verify(underlying).error(s " foo \n bar {} " , arg1)
83+ }
84+ " call the underlying logger's error method when the interpolated string is triple quoted and contains escape sequences" in {
85+ val f = fixture(_.isErrorEnabled, true )
86+ import f ._
87+ logger.error(s """ foo\nbar $arg1""" )
88+ verify(underlying).error(s """ foo\nbar {} """ , arg1)
89+ }
7790 }
7891
7992 " Calling error with a message and cause" should {
You can’t perform that action at this time.
0 commit comments