@@ -39,10 +39,11 @@ private object LoggerMacro {
3939 def errorMessageArgs (c : LoggerContext )(message : c.Expr [String ], args : c.Expr [Any ]* ) = {
4040 import c .universe ._
4141 val underlying = q " ${c.prefix}.underlying "
42+ val anyRefArgs = formatArgs(c)(args : _* )
4243 if (args.length == 2 )
43- q " if ( $underlying.isErrorEnabled) $underlying.error( $message, _root_.scala.Array( ${args (0 )}, ${args (1 )}): _*) "
44+ q " if ( $underlying.isErrorEnabled) $underlying.error( $message, _root_.scala.Array( ${anyRefArgs (0 )}, ${anyRefArgs (1 )}): _*) "
4445 else
45- q " if ( $underlying.isErrorEnabled) $underlying.error( $message, .. $args ) "
46+ q " if ( $underlying.isErrorEnabled) $underlying.error( $message, .. $anyRefArgs ) "
4647 }
4748
4849 def errorMessageMarker (c : LoggerContext )(marker : c.Expr [Marker ], message : c.Expr [String ]) = {
@@ -59,10 +60,11 @@ private object LoggerMacro {
5960 def errorMessageArgsMarker (c : LoggerContext )(marker : c.Expr [Marker ], message : c.Expr [String ], args : c.Expr [Any ]* ) = {
6061 import c .universe ._
6162 val underlying = q " ${c.prefix}.underlying "
63+ val anyRefArgs = formatArgs(c)(args : _* )
6264 if (args.length == 2 )
63- q " if ( $underlying.isErrorEnabled) $underlying.error( $marker, $message, _root_.scala.Array( ${args (0 )}, ${args (1 )}): _*) "
65+ q " if ( $underlying.isErrorEnabled) $underlying.error( $marker, $message, _root_.scala.Array( ${anyRefArgs (0 )}, ${anyRefArgs (1 )}): _*) "
6466 else
65- q " if ( $underlying.isErrorEnabled) $underlying.error( $marker, $message, .. $args ) "
67+ q " if ( $underlying.isErrorEnabled) $underlying.error( $marker, $message, .. $anyRefArgs ) "
6668 }
6769
6870 // Warn
@@ -81,10 +83,11 @@ private object LoggerMacro {
8183 def warnMessageArgs (c : LoggerContext )(message : c.Expr [String ], args : c.Expr [Any ]* ) = {
8284 import c .universe ._
8385 val underlying = q " ${c.prefix}.underlying "
86+ val anyRefArgs = formatArgs(c)(args : _* )
8487 if (args.length == 2 )
85- q " if ( $underlying.isWarnEnabled) $underlying.warn( $message, _root_.scala.Array( ${args (0 )}, ${args (1 )}): _*) "
88+ q " if ( $underlying.isWarnEnabled) $underlying.warn( $message, _root_.scala.Array( ${anyRefArgs (0 )}, ${anyRefArgs (1 )}): _*) "
8689 else
87- q " if ( $underlying.isWarnEnabled) $underlying.warn( $message, .. $args ) "
90+ q " if ( $underlying.isWarnEnabled) $underlying.warn( $message, .. $anyRefArgs ) "
8891 }
8992
9093 def warnMessageMarker (c : LoggerContext )(marker : c.Expr [Marker ], message : c.Expr [String ]) = {
@@ -101,10 +104,11 @@ private object LoggerMacro {
101104 def warnMessageArgsMarker (c : LoggerContext )(marker : c.Expr [Marker ], message : c.Expr [String ], args : c.Expr [Any ]* ) = {
102105 import c .universe ._
103106 val underlying = q " ${c.prefix}.underlying "
107+ val anyRefArgs = formatArgs(c)(args : _* )
104108 if (args.length == 2 )
105- q " if ( $underlying.isWarnEnabled) $underlying.warn( $marker, $message, _root_.scala.Array( ${args (0 )}, ${args (1 )}): _*) "
109+ q " if ( $underlying.isWarnEnabled) $underlying.warn( $marker, $message, _root_.scala.Array( ${anyRefArgs (0 )}, ${anyRefArgs (1 )}): _*) "
106110 else
107- q " if ( $underlying.isWarnEnabled) $underlying.warn( $marker, $message, .. $args ) "
111+ q " if ( $underlying.isWarnEnabled) $underlying.warn( $marker, $message, .. $anyRefArgs ) "
108112 }
109113
110114 // Info
@@ -123,10 +127,11 @@ private object LoggerMacro {
123127 def infoMessageArgs (c : LoggerContext )(message : c.Expr [String ], args : c.Expr [Any ]* ) = {
124128 import c .universe ._
125129 val underlying = q " ${c.prefix}.underlying "
130+ val anyRefArgs = formatArgs(c)(args : _* )
126131 if (args.length == 2 )
127- q " if ( $underlying.isInfoEnabled) $underlying.info( $message, _root_.scala.Array( ${args (0 )}, ${args (1 )}): _*) "
132+ q " if ( $underlying.isInfoEnabled) $underlying.info( $message, _root_.scala.Array( ${anyRefArgs (0 )}, ${anyRefArgs (1 )}): _*) "
128133 else
129- q " if ( $underlying.isInfoEnabled) $underlying.info( $message, .. $args ) "
134+ q " if ( $underlying.isInfoEnabled) $underlying.info( $message, .. $anyRefArgs ) "
130135 }
131136
132137 def infoMessageMarker (c : LoggerContext )(marker : c.Expr [Marker ], message : c.Expr [String ]) = {
@@ -143,10 +148,11 @@ private object LoggerMacro {
143148 def infoMessageArgsMarker (c : LoggerContext )(marker : c.Expr [Marker ], message : c.Expr [String ], args : c.Expr [Any ]* ) = {
144149 import c .universe ._
145150 val underlying = q " ${c.prefix}.underlying "
151+ val anyRefArgs = formatArgs(c)(args : _* )
146152 if (args.length == 2 )
147- q " if ( $underlying.isInfoEnabled) $underlying.info( $marker, $message, _root_.scala.Array( ${args (0 )}, ${args (1 )}): _*) "
153+ q " if ( $underlying.isInfoEnabled) $underlying.info( $marker, $message, _root_.scala.Array( ${anyRefArgs (0 )}, ${anyRefArgs (1 )}): _*) "
148154 else
149- q " if ( $underlying.isInfoEnabled) $underlying.info( $marker, $message, .. $args ) "
155+ q " if ( $underlying.isInfoEnabled) $underlying.info( $marker, $message, .. $anyRefArgs ) "
150156 }
151157
152158 // Debug
@@ -165,10 +171,11 @@ private object LoggerMacro {
165171 def debugMessageArgs (c : LoggerContext )(message : c.Expr [String ], args : c.Expr [Any ]* ) = {
166172 import c .universe ._
167173 val underlying = q " ${c.prefix}.underlying "
174+ val anyRefArgs = formatArgs(c)(args : _* )
168175 if (args.length == 2 )
169- q " if ( $underlying.isDebugEnabled) $underlying.debug( $message, _root_.scala.Array( ${args (0 )}, ${args (1 )}): _*) "
176+ q " if ( $underlying.isDebugEnabled) $underlying.debug( $message, _root_.scala.Array( ${anyRefArgs (0 )}, ${anyRefArgs (1 )}): _*) "
170177 else
171- q " if ( $underlying.isDebugEnabled) $underlying.debug( $message, .. $args ) "
178+ q " if ( $underlying.isDebugEnabled) $underlying.debug( $message, .. $anyRefArgs ) "
172179 }
173180
174181 def debugMessageMarker (c : LoggerContext )(marker : c.Expr [Marker ], message : c.Expr [String ]) = {
@@ -185,10 +192,11 @@ private object LoggerMacro {
185192 def debugMessageArgsMarker (c : LoggerContext )(marker : c.Expr [Marker ], message : c.Expr [String ], args : c.Expr [Any ]* ) = {
186193 import c .universe ._
187194 val underlying = q " ${c.prefix}.underlying "
195+ val anyRefArgs = formatArgs(c)(args : _* )
188196 if (args.length == 2 )
189- q " if ( $underlying.isDebugEnabled) $underlying.debug( $marker, $message, _root_.scala.Array( ${args (0 )}, ${args (1 )}): _*) "
197+ q " if ( $underlying.isDebugEnabled) $underlying.debug( $marker, $message, _root_.scala.Array( ${anyRefArgs (0 )}, ${anyRefArgs (1 )}): _*) "
190198 else
191- q " if ( $underlying.isDebugEnabled) $underlying.debug( $marker, $message, .. $args ) "
199+ q " if ( $underlying.isDebugEnabled) $underlying.debug( $marker, $message, .. $anyRefArgs ) "
192200 }
193201
194202 // Trace
@@ -207,10 +215,11 @@ private object LoggerMacro {
207215 def traceMessageArgs (c : LoggerContext )(message : c.Expr [String ], args : c.Expr [Any ]* ) = {
208216 import c .universe ._
209217 val underlying = q " ${c.prefix}.underlying "
218+ val anyRefArgs = formatArgs(c)(args : _* )
210219 if (args.length == 2 )
211- q " if ( $underlying.isTraceEnabled) $underlying.trace( $message, _root_.scala.Array( ${args (0 )}, ${args (1 )}): _*) "
220+ q " if ( $underlying.isTraceEnabled) $underlying.trace( $message, _root_.scala.Array( ${anyRefArgs (0 )}, ${anyRefArgs (1 )}): _*) "
212221 else
213- q " if ( $underlying.isTraceEnabled) $underlying.trace( $message, .. $args ) "
222+ q " if ( $underlying.isTraceEnabled) $underlying.trace( $message, .. $anyRefArgs ) "
214223 }
215224
216225 def traceMessageMarker (c : LoggerContext )(marker : c.Expr [Marker ], message : c.Expr [String ]) = {
@@ -227,10 +236,11 @@ private object LoggerMacro {
227236 def traceMessageArgsMarker (c : LoggerContext )(marker : c.Expr [Marker ], message : c.Expr [String ], args : c.Expr [Any ]* ) = {
228237 import c .universe ._
229238 val underlying = q " ${c.prefix}.underlying "
239+ val anyRefArgs = formatArgs(c)(args : _* )
230240 if (args.length == 2 )
231- q " if ( $underlying.isTraceEnabled) $underlying.trace( $marker, $message, _root_.scala.Array( ${args (0 )}, ${args (1 )}): _*) "
241+ q " if ( $underlying.isTraceEnabled) $underlying.trace( $marker, $message, _root_.scala.Array( ${anyRefArgs (0 )}, ${anyRefArgs (1 )}): _*) "
232242 else
233- q " if ( $underlying.isTraceEnabled) $underlying.trace( $marker, $message, .. $args ) "
243+ q " if ( $underlying.isTraceEnabled) $underlying.trace( $marker, $message, .. $anyRefArgs ) "
234244 }
235245
236246 /** Checks whether `messsage` is an interpolated string and transforms it into SLF4J string interpolation. */
@@ -246,14 +256,18 @@ private object LoggerMacro {
246256 .map(str => if (args.nonEmpty) str.replace(" {}" , " \\ {}" ) else str)
247257 .mkString(" {}" )
248258
249- val formatArgs = args map { arg =>
250- c.Expr [AnyRef ](if (arg.tpe <:< weakTypeOf[AnyRef ]) arg else q " $arg.asInstanceOf[_root_.scala.AnyRef] " )
251- }
259+ val formatArgs = args.map(t => c.Expr [Any ](t))
252260
253261 (c.Expr (q " $format" ), formatArgs)
254262
255263 case _ => (message, Seq .empty)
256264 }
257265 }
258266
267+ private def formatArgs (c : LoggerContext )(args : c.Expr [Any ]* ) = {
268+ import c .universe ._
269+ args.map { arg =>
270+ c.Expr [AnyRef ](if (arg.tree.tpe <:< weakTypeOf[AnyRef ]) arg.tree else q " $arg.asInstanceOf[_root_.scala.AnyRef] " )
271+ }
272+ }
259273}
0 commit comments