@@ -83,6 +83,16 @@ private[scalalogging] object LoggerTakingImplicitMacro {
8383 }
8484 }
8585
86+ def errorCode [A ](c : LoggerContext [A ])(body : c.Expr [Unit ])(a : c.Expr [A ]): c.universe.Tree = {
87+ import c .universe ._
88+ val underlying = q " ${c.prefix}.underlying "
89+ val canLogEv = q " ${c.prefix}.canLogEv "
90+ q """ if ( $underlying.isErrorEnabled) {
91+ $underlying.error( $canLogEv.logMessage( $body))
92+ $canLogEv.afterLog( $a)
93+ } """
94+ }
95+
8696 // Warn
8797
8898 def warnMessage [A ](c : LoggerContext [A ])(message : c.Expr [String ])(a : c.Expr [A ]): c.universe.Tree = {
@@ -159,6 +169,16 @@ private[scalalogging] object LoggerTakingImplicitMacro {
159169 }
160170 }
161171
172+ def warnCode [A ](c : LoggerContext [A ])(body : c.Expr [Unit ])(a : c.Expr [A ]): c.universe.Tree = {
173+ import c .universe ._
174+ val underlying = q " ${c.prefix}.underlying "
175+ val canLogEv = q " ${c.prefix}.canLogEv "
176+ q """ if ( $underlying.isWarnEnabled) {
177+ $underlying.warn( $canLogEv.logMessage( $body))
178+ $canLogEv.afterLog( $a)
179+ } """
180+ }
181+
162182 // Info
163183
164184 def infoMessage [A ](c : LoggerContext [A ])(message : c.Expr [String ])(a : c.Expr [A ]): c.universe.Tree = {
@@ -235,6 +255,16 @@ private[scalalogging] object LoggerTakingImplicitMacro {
235255 }
236256 }
237257
258+ def infoCode [A ](c : LoggerContext [A ])(body : c.Expr [Unit ])(a : c.Expr [A ]): c.universe.Tree = {
259+ import c .universe ._
260+ val underlying = q " ${c.prefix}.underlying "
261+ val canLogEv = q " ${c.prefix}.canLogEv "
262+ q """ if ( $underlying.isInfoEnabled) {
263+ $underlying.info( $canLogEv.logMessage( $body))
264+ $canLogEv.afterLog( $a)
265+ } """
266+ }
267+
238268 // Debug
239269
240270 def debugMessage [A ](c : LoggerContext [A ])(message : c.Expr [String ])(a : c.Expr [A ]): c.universe.Tree = {
@@ -311,6 +341,17 @@ private[scalalogging] object LoggerTakingImplicitMacro {
311341 }
312342 }
313343
344+ def debugCode [A ](c : LoggerContext [A ])(body : c.Expr [Unit ])(a : c.Expr [A ]): c.universe.Tree = {
345+ import c .universe ._
346+ val underlying = q " ${c.prefix}.underlying "
347+ val canLogEv = q " ${c.prefix}.canLogEv "
348+ q """ if ( $underlying.isDebugEnabled) {
349+ $underlying.debug( $canLogEv.logMessage( $body))
350+ $canLogEv.afterLog( $a)
351+ } """
352+ }
353+
354+
314355 // Trace
315356
316357 def traceMessage [A ](c : LoggerContext [A ])(message : c.Expr [String ])(a : c.Expr [A ]): c.universe.Tree = {
@@ -386,4 +427,14 @@ private[scalalogging] object LoggerTakingImplicitMacro {
386427 } """
387428 }
388429 }
430+
431+ def traceCode [A ](c : LoggerContext [A ])(body : c.Expr [Unit ])(a : c.Expr [A ]): c.universe.Tree = {
432+ import c .universe ._
433+ val underlying = q " ${c.prefix}.underlying "
434+ val canLogEv = q " ${c.prefix}.canLogEv "
435+ q """ if ( $underlying.isTraceEnabled) {
436+ $underlying.trace( $canLogEv.logMessage( $body))
437+ $canLogEv.afterLog( $a)
438+ } """
439+ }
389440}
0 commit comments