Logger Resolvers

The easiest way to get at a logger is to use LoggerFactory. This looks like the SLF4J version, but is more flexible because it uses a LoggerResolver type class under the hood.

import com.tersesystems.blindsight.LoggerFactory

val loggerFromName  = LoggerFactory.getLogger("some.Logger")
val loggerFromClass = LoggerFactory.getLogger(getClass)

There is also a macro based version which finds the enclosing class name and hands it to you:

val loggerFromEnclosing = LoggerFactory.getLogger

Finally, you also have the option of creating your own LoggerResolver. This is useful when you want to get away from class based logging, and use a naming strategy based on a correlation id.

For example, you can resolve a logger using a request:

implicit val requestToResolver: LoggerResolver[Request] = new LoggerResolver[Request] {
  override def resolveLogger(instance: Request): org.slf4j.Logger = {
    org.slf4j.LoggerFactory.getLogger("requests." + instance.id)

And from then on, you can do:

def loggerFromRequest(request: Request): Unit = {
  val logger = com.tersesystems.blindsight.LoggerFactory.getLogger(request)
The source code for this page can be found here.