mirror of https://github.com/sbt/sbt.git
error,warn,info,debug commands to set log level, useful in conjunction with early combinator --. Fixes #806.
This commit is contained in:
parent
f461b94e73
commit
c2b319e977
|
|
@ -37,6 +37,29 @@ object BasicCommandStrings
|
|||
|
||||
def exitBrief = "Terminates the build."
|
||||
|
||||
def logLevelHelp =
|
||||
{
|
||||
val levels = Level.values.toSeq
|
||||
val levelList = levels.mkString(", ")
|
||||
val brief = ("<log-level>", "Sets the logging level to 'log-level'. Valid levels: " + levelList)
|
||||
val detailed = levels.map(l => (l.toString, logLevelDetail(l))).toMap
|
||||
Help(brief, detailed)
|
||||
}
|
||||
private[this] def logLevelDetail(level: Level.Value): String =
|
||||
s"""$level
|
||||
|
||||
Sets the global logging level to $level.
|
||||
This will be used as the default level for logging from commands, settings, and tasks.
|
||||
Any explicit `logLevel` configuration in a project overrides this setting.
|
||||
|
||||
${runEarly(level.toString)}
|
||||
|
||||
Sets the global logging level as described above, but does so before any other commands are executed on startup, including project loading.
|
||||
This is useful as a startup option:
|
||||
* it takes effect before any logging occurs
|
||||
* if no other commands are passed, interactive mode is still entered
|
||||
"""
|
||||
|
||||
def runEarly(command: String) = {
|
||||
val sep = if(command.isEmpty || Character.isLetter(command.charAt(0))) "" else " "
|
||||
s"$EarlyCommand$sep$command"
|
||||
|
|
|
|||
|
|
@ -86,6 +86,14 @@ object LogManager
|
|||
s
|
||||
}
|
||||
|
||||
def setGlobalLogLevel(s: State, level: Level.Value): State = {
|
||||
s.globalLogging.full match {
|
||||
case a: AbstractLogger => a.setLevel(level)
|
||||
case _ => ()
|
||||
}
|
||||
s.put(BasicKeys.explicitGlobalLogLevels, true).put(Keys.logLevel.key, level)
|
||||
}
|
||||
|
||||
private[this] def setExplicitGlobalLogLevels(s: State, flag: Boolean): State =
|
||||
s.put(BasicKeys.explicitGlobalLogLevels, flag)
|
||||
private[this] def hasExplicitGlobalLogLevels(s: State): Boolean =
|
||||
|
|
|
|||
|
|
@ -85,11 +85,11 @@ object BuiltinCommands
|
|||
{
|
||||
def initialAttributes = AttributeMap.empty
|
||||
|
||||
def ConsoleCommands: Seq[Command] = Seq(ignore, exit, IvyConsole.command, early, act, nop)
|
||||
def ScriptCommands: Seq[Command] = Seq(ignore, exit, Script.command, early, act, nop)
|
||||
def ConsoleCommands: Seq[Command] = Seq(ignore, exit, IvyConsole.command, setLogLevel, early, act, nop)
|
||||
def ScriptCommands: Seq[Command] = Seq(ignore, exit, Script.command, setLogLevel, early, act, nop)
|
||||
def DefaultCommands: Seq[Command] = Seq(ignore, help, about, tasks, settingsCommand, loadProject,
|
||||
projects, project, reboot, read, history, set, sessionCommand, inspect, loadProjectImpl, loadFailed, Cross.crossBuild, Cross.switchVersion,
|
||||
setOnFailure, clearOnFailure, stashOnFailure, popOnFailure,
|
||||
setOnFailure, clearOnFailure, stashOnFailure, popOnFailure, setLogLevel,
|
||||
ifLast, multi, shell, continuous, eval, alias, append, last, lastGrep, export, boot, nop, call, exit, early, initialize, act) ++
|
||||
compatCommands
|
||||
def DefaultBootCommands: Seq[String] = LoadProject :: (IfLast + " " + Shell) :: Nil
|
||||
|
|
@ -98,6 +98,9 @@ object BuiltinCommands
|
|||
|
||||
def about = Command.command(AboutCommand, aboutBrief, aboutDetailed) { s => s.log.info(aboutString(s)); s }
|
||||
|
||||
def setLogLevel = Command.arb(const(logLevelParser), logLevelHelp)(LogManager.setGlobalLogLevel)
|
||||
private[this] def logLevelParser: Parser[Level.Value] = oneOf(Level.values.toSeq.map(v => v.toString ^^^ v))
|
||||
|
||||
// This parser schedules the default boot commands unless overridden by an alias
|
||||
def bootParser(s: State) =
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue