From 494553461416a9e9ad89e88faab6c8c95e0cc53f Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Sun, 29 Jan 2012 14:36:27 -0500 Subject: [PATCH] split command core to main/command/ --- util/collection/Settings.scala | 2 +- util/control/MessageOnlyException.scala | 9 ++++++- util/log/GlobalLogging.scala | 27 +++++++++++++++++++ util/log/MainLogging.scala | 36 +++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 util/log/GlobalLogging.scala create mode 100644 util/log/MainLogging.scala diff --git a/util/collection/Settings.scala b/util/collection/Settings.scala index 4111c9082..d8945a787 100644 --- a/util/collection/Settings.scala +++ b/util/collection/Settings.scala @@ -177,7 +177,7 @@ trait Init[Scope] if(dist < 0) None else Some(dist) } - final class Uninitialized(val undefined: Seq[Undefined], msg: String) extends Exception(msg) + final class Uninitialized(val undefined: Seq[Undefined], override val toString: String) extends Exception(toString) final class Undefined(val definingKey: ScopedKey[_], val referencedKey: ScopedKey[_]) final class RuntimeUndefined(val undefined: Seq[Undefined]) extends RuntimeException("References to undefined settings at runtime.") def Undefined(definingKey: ScopedKey[_], referencedKey: ScopedKey[_]): Undefined = new Undefined(definingKey, referencedKey) diff --git a/util/control/MessageOnlyException.scala b/util/control/MessageOnlyException.scala index 6791a9339..7fa43746d 100644 --- a/util/control/MessageOnlyException.scala +++ b/util/control/MessageOnlyException.scala @@ -4,4 +4,11 @@ package sbt final class MessageOnlyException(override val toString: String) extends RuntimeException(toString) -final class NoMessageException extends RuntimeException \ No newline at end of file + +/** A dummy exception for the top-level exception handler to know that an exception +* has been handled, but is being passed further up to indicate general failure. */ +final class AlreadyHandledException extends RuntimeException + +/** A marker trait for a top-level exception handler to know that this exception +* doesn't make sense to display. */ +trait UnprintableException extends Throwable \ No newline at end of file diff --git a/util/log/GlobalLogging.scala b/util/log/GlobalLogging.scala new file mode 100644 index 000000000..e54b00a00 --- /dev/null +++ b/util/log/GlobalLogging.scala @@ -0,0 +1,27 @@ +/* sbt -- Simple Build Tool + * Copyright 2010 Mark Harrah + */ +package sbt + + import java.io.{File, PrintWriter} + +final case class GlobalLogging(full: Logger, backed: ConsoleLogger, backing: GlobalLogBacking) +final case class GlobalLogBacking(file: File, last: Option[File], newLogger: (PrintWriter, GlobalLogBacking) => GlobalLogging, newBackingFile: () => File) +{ + def shift(newFile: File) = GlobalLogBacking(newFile, Some(file), newLogger, newBackingFile) + def shiftNew() = shift(newBackingFile()) + def unshift = GlobalLogBacking(last getOrElse file, None, newLogger, newBackingFile) +} +object GlobalLogBacking +{ + def apply(newLogger: (PrintWriter, GlobalLogBacking) => GlobalLogging, newBackingFile: => File): GlobalLogBacking = + GlobalLogBacking(newBackingFile, None, newLogger, newBackingFile _) +} +object GlobalLogging +{ + def initial(newLogger: (PrintWriter, GlobalLogBacking) => GlobalLogging, newBackingFile: => File): GlobalLogging = + { + val log = ConsoleLogger() + GlobalLogging(log, log, GlobalLogBacking(newLogger, newBackingFile)) + } +} \ No newline at end of file diff --git a/util/log/MainLogging.scala b/util/log/MainLogging.scala new file mode 100644 index 000000000..b07abf4e3 --- /dev/null +++ b/util/log/MainLogging.scala @@ -0,0 +1,36 @@ +package sbt + + import java.io.PrintWriter + +object MainLogging +{ + def multiLogger(config: MultiLoggerConfig): Logger = + { + import config._ + val multi = new MultiLogger(console :: backed :: extra) + // sets multi to the most verbose for clients that inspect the current level + multi setLevel Level.unionAll(backingLevel :: screenLevel :: extra.map(_.getLevel)) + // set the specific levels + console setLevel screenLevel + backed setLevel backingLevel + console setTrace screenTrace + backed setTrace backingTrace + multi: Logger + } + def globalDefault(writer: PrintWriter, backing: GlobalLogBacking): GlobalLogging = + { + val backed = defaultBacked()(writer) + val full = multiLogger(defaultMultiConfig( backed ) ) + GlobalLogging(full, backed, backing) + } + + def defaultMultiConfig(backing: AbstractLogger): MultiLoggerConfig = + new MultiLoggerConfig(defaultScreen, backing, Nil, Level.Info, Level.Debug, -1, Int.MaxValue) + + def defaultScreen: AbstractLogger = ConsoleLogger() + + def defaultBacked(useColor: Boolean = ConsoleLogger.formatEnabled): PrintWriter => ConsoleLogger = + to => ConsoleLogger(ConsoleLogger.printWriterOut(to), useColor = useColor) // TODO: should probably filter ANSI codes when useColor=false +} + +final case class MultiLoggerConfig(console: AbstractLogger, backed: AbstractLogger, extra: List[AbstractLogger], screenLevel: Level.Value, backingLevel: Level.Value, screenTrace: Int, backingTrace: Int) \ No newline at end of file