summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorTobias Roeser <le.petit.fou@web.de>2018-10-29 14:03:26 +0100
committerTobias Roeser <le.petit.fou@web.de>2018-10-30 09:31:42 +0100
commitc92eb6f6f2c482e9fe838bc0f4de97d7c2c19646 (patch)
tree57b85df863b959311246511ea0dcbf451c3b374b /main
parent56d4537bec253ea00d59a148522add366c11dece (diff)
downloadmill-c92eb6f6f2c482e9fe838bc0f4de97d7c2c19646.tar.gz
mill-c92eb6f6f2c482e9fe838bc0f4de97d7c2c19646.tar.bz2
mill-c92eb6f6f2c482e9fe838bc0f4de97d7c2c19646.zip
Added additional debug log channel (default: log-file only)
Diffstat (limited to 'main')
-rw-r--r--main/core/src/mill/eval/Evaluator.scala2
-rw-r--r--main/core/src/mill/util/Logger.scala51
-rw-r--r--main/src/mill/main/MainModule.scala2
-rw-r--r--main/src/mill/main/MainRunner.scala3
-rw-r--r--main/src/mill/main/ReplApplyHandler.scala3
-rw-r--r--main/test/src/mill/util/TestEvaluator.scala2
6 files changed, 45 insertions, 18 deletions
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)