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

ill-contrib-flyway_2.13.0.9.6-19-ad6b16.source-code.ConsoleLog.scala Maven / Gradle / Ivy

There is a newer version: 0.12.4
Show newest version
package mill.contrib.flyway

import org.flywaydb.core.api.logging.Log
import org.flywaydb.core.api.logging.LogCreator

/**
  * Adapted from https://github.com/flyway/flyway/blob/25f562283e45d717bf56e44fb9988b4adc98a0ef/flyway-commandline/src/main/java/org/flywaydb/commandline/ConsoleLog.java
  */

/**
  * Wrapper around a simple Console output.
  */
object ConsoleLog {

  object Level extends Enumeration {
    type Level = Value
    val DEBUG, INFO, WARN = Value
  }
}

/**
  * Creates a new Console Log.
  *
  * @param level the log level.
  */
class ConsoleLog(val level: ConsoleLog.Level.Level) extends Log {
  override def isDebugEnabled: Boolean = level eq ConsoleLog.Level.DEBUG

  override def debug(message: String): Unit = {
    if (isDebugEnabled) System.out.println("DEBUG: " + message)
  }

  override def info(message: String): Unit = {
    if (level.compareTo(ConsoleLog.Level.INFO) <= 0) System.out.println(message)
  }

  override def warn(message: String): Unit = {
    System.out.println("WARNING: " + message)
  }

  override def error(message: String): Unit = {
    System.err.println("ERROR: " + message)
  }

  override def error(message: String, e: Exception): Unit = {
    System.err.println("ERROR: " + message)
    e.printStackTrace(System.err)
  }
}



/**
  * Log Creator for the Command-Line console.
  */
class ConsoleLogCreator(val level: ConsoleLog.Level.Level) extends LogCreator {
  override def createLogger(clazz: Class[_]): Log = new ConsoleLog(level)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy