mirror of https://github.com/sbt/sbt.git
set global logging levels from project settings if not already explicitly set
This commit is contained in:
parent
5498275ebd
commit
55832b3a03
|
|
@ -66,6 +66,25 @@ object LogManager
|
|||
case _ => key // should never get here
|
||||
}
|
||||
|
||||
// if global logging levels are not explicitly set, set them from project settings
|
||||
private[sbt] def setGlobalLogLevels(s: State, data: Settings[Scope]): State =
|
||||
if(hasExplicitGlobalLogLevels(s))
|
||||
s
|
||||
else {
|
||||
val logging = s.globalLogging
|
||||
def get[T](key: SettingKey[T]) = key in GlobalScope get data
|
||||
def transfer(l: AbstractLogger, traceKey: SettingKey[Int], levelKey: SettingKey[Level.Value]) {
|
||||
get(traceKey).foreach(l.setTrace)
|
||||
get(levelKey).foreach(l.setLevel)
|
||||
}
|
||||
logging.full match {
|
||||
case a: AbstractLogger => transfer(a, traceLevel, logLevel)
|
||||
case _ => ()
|
||||
}
|
||||
transfer(logging.backed, persistTraceLevel, persistLogLevel)
|
||||
s
|
||||
}
|
||||
|
||||
private[this] def setExplicitGlobalLogLevels(s: State, flag: Boolean): State =
|
||||
s.put(BasicKeys.explicitGlobalLogLevels, flag)
|
||||
private[this] def hasExplicitGlobalLogLevels(s: State): Boolean =
|
||||
|
|
|
|||
|
|
@ -223,8 +223,9 @@ object Project extends ProjectExtra
|
|||
val (onLoad, onUnload) = getHooks(structure.data)
|
||||
val newAttrs = unloaded.attributes.put(stateBuildStructure, structure).put(sessionSettings, session).put(Keys.onUnload.key, onUnload)
|
||||
val newState = unloaded.copy(attributes = newAttrs)
|
||||
onLoad(updateCurrent( newState ))
|
||||
onLoad(LogManager.setGlobalLogLevels(updateCurrent( newState ), structure.data))
|
||||
}
|
||||
|
||||
def orIdentity[T](opt: Option[T => T]): T => T = opt getOrElse idFun
|
||||
def getHook[T](key: SettingKey[T => T], data: Settings[Scope]): T => T = orIdentity(key in GlobalScope get data)
|
||||
def getHooks(data: Settings[Scope]): (State => State, State => State) = (getHook(Keys.onLoad, data), getHook(Keys.onUnload, data))
|
||||
|
|
|
|||
Loading…
Reference in New Issue