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 +++++++++++++++++++++-------- main/src/mill/main/MainModule.scala | 2 +- main/src/mill/main/MainRunner.scala | 3 +- main/src/mill/main/ReplApplyHandler.scala | 3 +- main/test/src/mill/util/TestEvaluator.scala | 2 +- 6 files changed, 45 insertions(+), 18 deletions(-) (limited to 'main') 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() diff --git a/main/src/mill/main/MainModule.scala b/main/src/mill/main/MainModule.scala index 7e326860..929ad3dc 100644 --- a/main/src/mill/main/MainModule.scala +++ b/main/src/mill/main/MainModule.scala @@ -178,7 +178,7 @@ trait MainModule extends mill.Module{ // When using `show`, redirect all stdout of the evaluated tasks so the // printed JSON is the only thing printed to stdout. log = evaluator.log match{ - case PrintLogger(c1, d, c2, o, i, e, in) => PrintLogger(c1, d, c2, e, i, e, in) + case PrintLogger(c1, d, c2, o, i, e, in, de) => PrintLogger(c1, d, c2, e, i, e, in, de) case l => l } ), diff --git a/main/src/mill/main/MainRunner.scala b/main/src/mill/main/MainRunner.scala index 58c47998..34151ab4 100644 --- a/main/src/mill/main/MainRunner.scala +++ b/main/src/mill/main/MainRunner.scala @@ -80,7 +80,8 @@ class MainRunner(val config: ammonite.main.Cli.Config, outprintStream, errPrintStream, errPrintStream, - stdIn + stdIn, + debugEnabled = false // TODO: read from cmdline args ), env ) diff --git a/main/src/mill/main/ReplApplyHandler.scala b/main/src/mill/main/ReplApplyHandler.scala index 59a6780b..2cf0c6f1 100644 --- a/main/src/mill/main/ReplApplyHandler.scala +++ b/main/src/mill/main/ReplApplyHandler.scala @@ -31,7 +31,8 @@ object ReplApplyHandler{ System.out, System.err, System.err, - System.in + System.in, + debugEnabled = false ) ) ) diff --git a/main/test/src/mill/util/TestEvaluator.scala b/main/test/src/mill/util/TestEvaluator.scala index 1a114947..6e7fe484 100644 --- a/main/test/src/mill/util/TestEvaluator.scala +++ b/main/test/src/mill/util/TestEvaluator.scala @@ -26,7 +26,7 @@ class TestEvaluator(module: TestUtil.BaseModule) // val logger = DummyLogger val logger = new PrintLogger( colored = true, disableTicker=false, - ammonite.util.Colors.Default, System.out, System.out, System.err, System.in + ammonite.util.Colors.Default, System.out, System.out, System.err, System.in, debugEnabled = false ) val evaluator = new Evaluator(Ctx.defaultHome, outPath, TestEvaluator.externalOutPath, module, logger) -- cgit v1.2.3