首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何找到产生特定输出的任务?

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

Stack Overflow用户
提问于 2014-07-08 17:27:07
回答 2查看 100关注 0票数 0

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

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

EN

回答 2

Stack Overflow用户

发布于 2014-07-08 21:52:04

我不知道sbt是否提供了一种串行执行任务的模式。我对此表示怀疑,因为毕竟这是sbt的主要特性,即并行触发任务。

您可以使用debug查看幕后发生的事情。

代码语言:javascript
复制
> 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命令。

代码语言:javascript
复制
> 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

代码语言:javascript
复制
> 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
票数 0
EN

Stack Overflow用户

发布于 2014-07-08 23:49:54

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

代码语言:javascript
复制
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)
  }
}

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24628284

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档