Sha256: 6170b31332efcd0cc10f34d981b0723f345507782d989ed12f4ef741a0c23a98

Contents?: true

Size: 1.94 KB

Versions: 16

Compression:

Stored size: 1.94 KB

Contents

package s3.website

import scala.util.Try

class Logger(val verboseOutput: Boolean) {
  def debug(msg: String) = if (verboseOutput) log(Debug, msg)
  def info(msg: String) = log(Info, msg)
  def fail(msg: String) = log(Failure, msg)

  def info(report: SuccessReport) = log(Success, report.reportMessage)
  def info(report: ErrorReport) = fail(report.reportMessage)

  def pending(msg: String) = log(Wait, msg)

  private def log(logType: LogType, msgRaw: String): Try[Unit] = {
    val msg = msgRaw.replaceAll("\\n", "\n       ") // Indent new lines, so that they arrange nicely with other log lines
    Try(println(s"[$logType] $msg"))
  }

  sealed trait LogType {
    val prefix: String
    override def toString = prefix
  }
  case object Debug extends LogType {
    val prefix = "debg".cyan
  }
  case object Info extends LogType {
    val prefix = "info".blue
  }
  case object Success extends LogType {
    val prefix = "succ".green
  }
  case object Failure extends LogType {
    val prefix = "fail".red
  }
  case object Wait extends LogType {
    val prefix = "wait".yellow
  }

  /**
   * Idea copied from https://github.com/ktoso/scala-rainbow.
   */
  implicit class RainbowString(val s: String) {
    import Console._

    /** Colorize the given string foreground to ANSI black */
    def black = BLACK + s + RESET
    /** Colorize the given string foreground to ANSI red */
    def red = RED + s + RESET
    /** Colorize the given string foreground to ANSI red */
    def green = GREEN + s + RESET
    /** Colorize the given string foreground to ANSI red */
    def yellow = YELLOW + s + RESET
    /** Colorize the given string foreground to ANSI red */
    def blue = BLUE + s + RESET
    /** Colorize the given string foreground to ANSI red */
    def magenta = MAGENTA + s + RESET
    /** Colorize the given string foreground to ANSI red */
    def cyan = CYAN + s + RESET
    /** Colorize the given string foreground to ANSI red */
    def white = WHITE + s + RESET
  }
}

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
s3_website-2.7.3 src/main/scala/s3/website/Logger.scala
s3_website-2.7.2 src/main/scala/s3/website/Logger.scala
s3_website-2.7.1 src/main/scala/s3/website/Logger.scala
s3_website-2.7.0 src/main/scala/s3/website/Logger.scala
s3_website-2.6.1 src/main/scala/s3/website/Logger.scala
s3_website-2.6.0 src/main/scala/s3/website/Logger.scala
s3_website-2.5.1 src/main/scala/s3/website/Logger.scala
s3_website-2.5.0 src/main/scala/s3/website/Logger.scala
s3_website-2.4.0 src/main/scala/s3/website/Logger.scala
s3_website-2.3.1 src/main/scala/s3/website/Logger.scala
s3_website-2.3.0 src/main/scala/s3/website/Logger.scala
s3_website-2.2.0 src/main/scala/s3/website/Logger.scala
s3_website-2.1.16 src/main/scala/s3/website/Logger.scala
s3_website-2.1.15 src/main/scala/s3/website/Logger.scala
s3_website-2.1.14 src/main/scala/s3/website/Logger.scala
s3_website-2.1.13 src/main/scala/s3/website/Logger.scala