In order to inject loggers into my classes with the appropriate class name, I use this handy trick:
import org.slf4j.Logger
import scala.reflect.{classTag, ClassTag}
trait LoggerVendor {
def getLogger(cls: Class[_]): Logger
def withLogger[T : ClassTag](build: Logger => T): T = {
val logger = getLogger(classTag[T].runtimeClass)
build(logger)
}
}
class MyService(logger: Logger) {
def doSomething(): Unit = {
logger.info("Hello")
}
}
import com.softwaremill.macwire._
class MyModule(loggerVendor: LoggerVendor) {
lazy val myService: MyService = loggerVendor.withLogger { _ =>
wire[MyService]
}
}
However, when I upgraded to Scala 2.13, I started seeing that the loggerVendor.withLogger{_ => wire[MyService]} causes the following compiler warning:
[warn] ... Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method validateOrThrow,
[warn] or remove the empty argument list from its definition (Java-defined methods are exempt).
[warn] In Scala 3, an unapplied method like this will be eta-expanded into a function.
This was the initial reason for #174, but it appears that there was another bug related to this that was fixed instead.
In order to inject loggers into my classes with the appropriate class name, I use this handy trick:
However, when I upgraded to Scala 2.13, I started seeing that the
loggerVendor.withLogger{_ => wire[MyService]}causes the following compiler warning:This was the initial reason for #174, but it appears that there was another bug related to this that was fixed instead.