From be1bdbb350c7a69a3d84be43bc9c1d4330b3e2ba Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Fri, 10 Jun 2011 23:40:25 -0400 Subject: [PATCH] use current project's logLevel for command logging --- main/Main.scala | 10 ++++++++-- main/Output.scala | 12 ++++++------ main/Project.scala | 10 +++++----- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/main/Main.scala b/main/Main.scala index dde26e91a..d764099e2 100644 --- a/main/Main.scala +++ b/main/Main.scala @@ -294,15 +294,21 @@ object BuiltinCommands s } def lastGrep = Command(LastGrepCommand, lastGrepBrief, lastGrepDetailed)(lastGrepParser) { case (s,(pattern,sk)) => - Output.lastGrep(sk, Project.structure(s).streams, pattern) + val (str, ref) = extractLast(s) + Output.lastGrep(sk, str, pattern, ref) s } + def extractLast(s: State) = { + val ext = Project.extract(s) + (ext.structure.streams, Select(ext.currentRef)) + } def inspectParser = (s: State) => token((Space ~> ("actual" ^^^ true)) ?? false) ~ spacedKeyParser(s) val spacedKeyParser = (s: State) => Act.requireSession(s, token(Space) ~> Act.scopedKeyParser(s)) val optSpacedKeyParser = (s: State) => spacedKeyParser(s).? def lastGrepParser(s: State) = Act.requireSession(s, (token(Space) ~> token(NotSpace, "")) ~ optSpacedKeyParser(s)) def last = Command(LastCommand, lastBrief, lastDetailed)(optSpacedKeyParser) { (s,sk) => - Output.last(sk, Project.structure(s).streams) + val (str, ref) = extractLast(s) + Output.last(sk, str, ref) s } diff --git a/main/Output.scala b/main/Output.scala index 6a853f75a..1e7804189 100644 --- a/main/Output.scala +++ b/main/Output.scala @@ -23,16 +23,16 @@ object Output None } - def last(key: Option[ScopedKey[_]], mgr: Streams): Unit = - printLines(lastLines(key, mgr)) + def last(key: Option[ScopedKey[_]], mgr: Streams, ref: ScopeAxis[ProjectRef]): Unit = + printLines(lastLines(key, mgr, ref)) def printLines(lines: Seq[String]) = lines foreach println - def lastGrep(key: Option[ScopedKey[_]], mgr: Streams, patternString: String) + def lastGrep(key: Option[ScopedKey[_]], mgr: Streams, patternString: String, ref: ScopeAxis[ProjectRef]) { val pattern = Pattern.compile(patternString) - printLines(lastLines(key, mgr).flatMap(showMatches(pattern)) ) + printLines(lastLines(key, mgr, ref).flatMap(showMatches(pattern)) ) } - def lastLines(key: Option[ScopedKey[_]], mgr: Streams): Seq[String] = - lastLines(key getOrElse Project.globalLoggerKey, mgr) + def lastLines(key: Option[ScopedKey[_]], mgr: Streams, ref: ScopeAxis[ProjectRef]): Seq[String] = + lastLines(key getOrElse Project.globalLoggerKey(ref), mgr) def lastLines(key: ScopedKey[_], mgr: Streams): Seq[String] = mgr.use(key) { s => IO.readLines(s.readText( Project.fillTaskAxis(key) )) } } diff --git a/main/Project.scala b/main/Project.scala index aa2ae0514..d2bf12e2a 100644 --- a/main/Project.scala +++ b/main/Project.scala @@ -143,8 +143,8 @@ object Project extends Init[Scope] with ProjectExtra def updateCurrent(s0: State): State = { val structure = Project.structure(s0) - val s = installGlobalLogger(s0, structure) - val ref = Project.current(s) + val ref = Project.current(s0) + val s = installGlobalLogger(s0, structure, ref) val project = Load.getProject(structure.units, ref.build, ref.project) logger(s).info("Set current project to " + ref.project + " (in build " + ref.build +")") def get[T](k: SettingKey[T]): Option[T] = k in ref get structure.data @@ -290,10 +290,10 @@ object Project extends Init[Scope] with ProjectExtra val extracted = Project.extract(state) EvaluateTask.evaluateTask(extracted.structure, taskKey, state, extracted.currentRef, checkCycles, maxWorkers) } - def globalLoggerKey = fillTaskAxis(ScopedKey(GlobalScope, streams.key)) - def installGlobalLogger(s: State, structure: BuildStructure): State = + def globalLoggerKey(ref: ScopeAxis[ResolvedReference]) = fillTaskAxis(ScopedKey(GlobalScope.copy(project = ref), streams.key)) + def installGlobalLogger(s: State, structure: BuildStructure, ref: ProjectRef): State = { - val str = structure.streams(globalLoggerKey) + val str = structure.streams(globalLoggerKey(Select(ref))) str.open() s.put(logged, str.log).addExitHook { str.close() } }