From fb1437cf36e8ae906f2b2b94e57a002fdbdca1e7 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Thu, 24 Oct 2013 16:34:16 -0400 Subject: [PATCH] Transfer logging,trace levels from old to new global loggers. --- main/command/src/main/scala/sbt/MainLoop.scala | 15 ++++++++++++++- util/log/src/main/scala/sbt/Logger.scala | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/main/command/src/main/scala/sbt/MainLoop.scala b/main/command/src/main/scala/sbt/MainLoop.scala index 58b0326cd..c81283678 100644 --- a/main/command/src/main/scala/sbt/MainLoop.scala +++ b/main/command/src/main/scala/sbt/MainLoop.scala @@ -65,9 +65,22 @@ object MainLoop def runWithNewLog(state: State, logBacking: GlobalLogBacking): RunNext = Using.fileWriter(append = true)(logBacking.file) { writer => val out = new java.io.PrintWriter(writer) - val loggedState = state.copy(globalLogging = state.globalLogging.newLogger(out, logBacking)) + val newLogging = state.globalLogging.newLogger(out, logBacking) + transferLevels(state, newLogging) + val loggedState = state.copy(globalLogging = newLogging) try run(loggedState) finally out.close() } + + /** Transfers logging and trace levels from the old global loggers to the new ones. */ + private[this] def transferLevels(state: State, logging: GlobalLogging) { + val old = state.globalLogging + Logger.transferLevels(old.backed, logging.backed) + (old.full, logging.full) match { // well, this is a hack + case (oldLog: AbstractLogger, newLog: AbstractLogger) => Logger.transferLevels(oldLog, newLog) + case _ => () + } + } + sealed trait RunNext final class ClearGlobalLog(val state: State) extends RunNext final class KeepGlobalLog(val state: State) extends RunNext diff --git a/util/log/src/main/scala/sbt/Logger.scala b/util/log/src/main/scala/sbt/Logger.scala index ce8201e9c..c556f620c 100644 --- a/util/log/src/main/scala/sbt/Logger.scala +++ b/util/log/src/main/scala/sbt/Logger.scala @@ -40,6 +40,11 @@ abstract class AbstractLogger extends Logger object Logger { + def transferLevels(oldLog: AbstractLogger, newLog: AbstractLogger) { + newLog.setLevel(oldLog.getLevel) + newLog.setTrace(oldLog.getTrace) + } + // make public in 0.13 private[sbt] val Null: AbstractLogger = new AbstractLogger { def getLevel: Level.Value = Level.Error