From c92eb6f6f2c482e9fe838bc0f4de97d7c2c19646 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Mon, 29 Oct 2018 14:03:26 +0100 Subject: Added additional debug log channel (default: log-file only) --- main/core/src/mill/eval/Evaluator.scala | 2 +- main/core/src/mill/util/Logger.scala | 51 ++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 14 deletions(-) (limited to 'main/core') diff --git a/main/core/src/mill/eval/Evaluator.scala b/main/core/src/mill/eval/Evaluator.scala index ded4afdd..2ffc469b 100644 --- a/main/core/src/mill/eval/Evaluator.scala +++ b/main/core/src/mill/eval/Evaluator.scala @@ -342,7 +342,7 @@ case class Evaluator(home: Path, def resolveLogger(logPath: Option[Path]): Logger = logPath match{ case None => log - case Some(path) => MultiLogger(log.colored, log, FileLogger(log.colored, path)) + case Some(path) => MultiLogger(log.colored, log, FileLogger(log.colored, path, debugEnabled = true)) } } diff --git a/main/core/src/mill/util/Logger.scala b/main/core/src/mill/util/Logger.scala index 37ae8577..34981766 100644 --- a/main/core/src/mill/util/Logger.scala +++ b/main/core/src/mill/util/Logger.scala @@ -5,20 +5,23 @@ import java.io._ import ammonite.ops.{Path, rm} import ammonite.util.Colors - /** * The standard logging interface of the Mill build tool. * - * Contains four primary logging methods, in order of increasing importance: + * Contains these primary logging methods, in order of increasing importance: + * + * - `debug` : internal debug messages normally not shown to the user; + * mostly useful when debugging issues * * - `ticker`: short-lived logging output where consecutive lines over-write - * each other; useful for information which is transient and disposable + * each other; useful for information which is transient and disposable * * - `info`: miscellaneous logging output which isn't part of the main output - * a user is looking for, but useful to provide context on what Mill is doing + * a user is looking for, but useful to provide context on what Mill is doing * * - `error`: logging output which represents problems the user should care - * about + * about + * * * Also contains the two forwarded stdout and stderr streams, for code executed * by Mill to use directly. Typically these correspond to the stdout and stderr, @@ -27,23 +30,30 @@ import ammonite.util.Colors */ trait Logger { def colored: Boolean + val errorStream: PrintStream val outputStream: PrintStream val inStream: InputStream + def info(s: String): Unit def error(s: String): Unit def ticker(s: String): Unit + def debug(s: String): Unit + def close(): Unit = () } object DummyLogger extends Logger { def colored = false + object errorStream extends PrintStream(_ => ()) object outputStream extends PrintStream(_ => ()) val inStream = new ByteArrayInputStream(Array()) + def info(s: String) = () def error(s: String) = () def ticker(s: String) = () + def debug(s: String) = () } class CallbackStream(wrapped: OutputStream, @@ -78,13 +88,17 @@ object PrintState{ case object Newline extends PrintState case object Middle extends PrintState } -case class PrintLogger(colored: Boolean, - disableTicker: Boolean, - colors: ammonite.util.Colors, - outStream: PrintStream, - infoStream: PrintStream, - errStream: PrintStream, - inStream: InputStream) extends Logger { + +case class PrintLogger( + colored: Boolean, + disableTicker: Boolean, + colors: ammonite.util.Colors, + outStream: PrintStream, + infoStream: PrintStream, + errStream: PrintStream, + inStream: InputStream, + debugEnabled: Boolean + ) extends Logger { var printState: PrintState = PrintState.Newline @@ -121,9 +135,14 @@ case class PrintLogger(colored: Boolean, printState = PrintState.Ticker } } + + def debug(s: String) = if (debugEnabled) { + printState = PrintState.Newline + errStream.println(colors.info()(s)) + } } -case class FileLogger(colored: Boolean, file: Path) extends Logger { +case class FileLogger(colored: Boolean, file: Path, debugEnabled: Boolean) extends Logger { private[this] var outputStreamUsed: Boolean = false lazy val outputStream = { @@ -141,6 +160,7 @@ case class FileLogger(colored: Boolean, file: Path) extends Logger { def info(s: String) = outputStream.println(s) def error(s: String) = outputStream.println(s) def ticker(s: String) = outputStream.println(s) + def debug(s: String) = if (debugEnabled) outputStream.println(s) val inStream: InputStream = DummyInputStream override def close() = { if (outputStreamUsed) @@ -198,6 +218,11 @@ case class MultiLogger(colored: Boolean, logger1: Logger, logger2: Logger) exten logger2.ticker(s) } + def debug(s: String) = { + logger1.debug(s) + logger2.debug(s) + } + override def close() = { logger1.close() logger2.close() -- cgit v1.2.3