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

时间:2014-07-08 09:27:07

标签: sbt

运行rpm:packageBin时,会向sbt日志记录打印一些错误消息。

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

2 个答案:

答案 0 :(得分:0)

我不知道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'.

我编写了一个抛出异常throwT的任务,一旦执行,sbt会捕获它并为该特定任务执行提供last

> throwT
[trace] Stack trace suppressed: run last *:throwT for the full output.
[error] (*:throwT) java.lang.IllegalStateException: exception
> last *:throwT
java.lang.IllegalStateException: exception
        at $a28d9b4066a1b28105c8$$anonfun$$sbtdef$1.apply(C:\dev\sandbox\sbt-sandbox\build.sbt:6)
        at $a28d9b4066a1b28105c8$$anonfun$$sbtdef$1.apply(C:\dev\sandbox\sbt-sandbox\build.sbt:5)
        at sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:45)
        at sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:45)
        at sbt.std.Transform$$anon$4.work(System.scala:64)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
        at sbt.Execute.work(Execute.scala:244)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
        at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
[error] (*:throwT) java.lang.IllegalStateException: exception

答案 1 :(得分:0)

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

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)
  }
}

添加时应该在每条消息之前打印范围,这是我相信你想要的。你当然可以进一步改进它。