Usage

To use a Blindsight Logger:

val logger = com.tersesystems.blindsight.LoggerFactory.getLogger
logger.info("I am an SLF4J-like logger")

But there’s a lot more, of course.

Examples

statement interpolation:

val dayOfWeek = "Monday"
val temp = 72 
val statement: Statement = st"It is ${dayOfWeek} and the temperature is ${temp} degrees."
logger.info(statement)

Structured logging using an internal DSL:

case class Winner(id: Long, numbers: List[Int])
case class Lotto(id: Long, winningNumbers: List[Int], winners: List[Winner], drawDate: Option[java.util.Date])

val winners = List(Winner(23, List(2, 45, 34, 23, 3, 5)), Winner(54, List(52, 3, 12, 11, 18, 22)))
val lotto = Lotto(5, List(2, 45, 34, 23, 7, 5, 3), winners, None)

import com.tersesystems.blindsight.AST._
import com.tersesystems.blindsight.DSL._
val complexArgument: BObject = "lotto" ->
    ("lotto-id" -> lotto.id) ~
      ("winning-numbers" -> lotto.winningNumbers) ~
      ("draw-date" -> lotto.drawDate.map(_.toString)) ~
      ("winners" -> lotto.winners.map(w => ("winner-id" -> w.id) ~ ("numbers" -> w.numbers)))
logger.info("Logs with an array as marker", complexArgument)

Fluent Logging:

logger.fluent.info.message("I am a fluent logger").log()

Semantic Logging:

logger.semantic[UserEvent].info(userEvent)

Flow Logging:

implicit def flowBehavior[B: ToArgument]: FlowBehavior[B] = new SimpleFlowBehavior 
val resultIsThree: Int = logger.flow.trace(1 + 2)

Conditional Logging:

logger.withCondition(booleanCondition).info("Only logs when condition is true")

logger.info.when(booleanCondition) { info => info("when true") }

Context Logging:

logger.withMarker("userId" -> userId).info("Logging with user id added as a context marker!")
The source code for this page can be found here.