All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softwaremill.macmemo.Debug.scala Maven / Gradle / Ivy

The newest version!
package com.softwaremill.macmemo

/**
 * Taken from MacWire https://github.com/adamw/macwire
 */
private[macmemo] class Debug {
  var ident = 0

  def apply(msg: => String): Unit = {
    if (enabled) {
      val prefix = "   " * ident
      println(s"$prefix[debug] $msg")
    }
  }

  def withBlock[T](msg: => String)(block: => T): T = {
    apply(msg)
    beginBlock()
    try {
      block
    } finally {
      endBlock()
    }
  }

  def beginBlock(): Unit = {
    ident += 1
  }

  def endBlock(): Unit = {
    ident -= 1
  }

  private val enabled = System.getProperty("macmemo.debug") != null
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy