Sbt 如何找到产生特定输出的任务?

Sbt 如何找到产生特定输出的任务?,sbt,Sbt,运行rpm:packageBin时,一些错误消息会打印到sbt日志中 有没有办法找出哪个子任务产生错误日志?例如,我可以获得执行任务的某种跟踪吗?也许有一种方法可以串行运行所有任务,而不是并行运行,并显示每个任务何时启动/停止?我不知道sbt是否提供了串行执行任务的模式。我怀疑这一点,毕竟这是sbt并行启动任务的主要特点 您可以使用debug查看封面下的内容 > help debug debug Sets the global logging level to debug

运行
rpm:packageBin
时,一些错误消息会打印到sbt日志中


有没有办法找出哪个子任务产生错误日志?例如,我可以获得执行任务的某种跟踪吗?也许有一种方法可以串行运行所有任务,而不是并行运行,并显示每个任务何时启动/停止?

我不知道sbt是否提供了串行执行任务的模式。我怀疑这一点,毕竟这是sbt并行启动任务的主要特点

您可以使用
debug
查看封面下的内容

> help debug
debug

        Sets the global logging level to debug.
        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.

--debug

        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
对于任何失败的任务,还提供了
last
命令

> help last
last
        Prints the logging for the previous command, typically at a more verbose level.

last <key>
        Prints the logging associated with the provided key.  The key typically refers to a task (for example, test:compile).  The logging that is displayed is restricted to the logging for that particular task.

        See also 'last-grep'.

我认为sbt不支持这种开箱即用的功能。但是,出于调试目的,您可以创建一个记录器并将其添加到
build.sbt
文件中的
extraLoggers

extraLoggers := {
  (key: ScopedKey[_]) => {
    val bl = new BasicLogger() {
       def control(event: ControlEvent.Value, message: => String) { log(Level.Info, message) }
       def logAll(events: Seq[LogEvent]) = events.foreach(log)
       def log(level: Level.Value, message: => String) = println("[ " + Scope.display(key.scope, "") + "] " + message)
       def success(message: => String): Unit = ()
       def trace(t: => Throwable): Unit = ()
    }
    Seq(bl)
  }
}
当添加时,它应该在每条消息之前打印范围,这是我相信你想要的。你当然可以进一步改进

extraLoggers := {
  (key: ScopedKey[_]) => {
    val bl = new BasicLogger() {
       def control(event: ControlEvent.Value, message: => String) { log(Level.Info, message) }
       def logAll(events: Seq[LogEvent]) = events.foreach(log)
       def log(level: Level.Value, message: => String) = println("[ " + Scope.display(key.scope, "") + "] " + message)
       def success(message: => String): Unit = ()
       def trace(t: => Throwable): Unit = ()
    }
    Seq(bl)
  }
}