如何为stream任务的日志成员设置SBT logLevel?

问题描述 投票:2回答:1

你怎么设置logLevel when using streams.value.log in an SBT task

例如,如何将此任务的日志抑制为qazxsw poi日志?:

Warn

在任务的内部和外部我尝试了各种logLevel设置,例如:

lazy val mainRunner = taskKey[Seq[File]]("Runs a main method")
lazy val mainRunnerSetting = mainRunner := {


  val logger = streams.value.log

  (runner in Compile).value.run(
    mainClass = "com.me.Main",
    classpath = (dependencyClasspath in Compile).value.files,
    log = logger,
    options = Array()
  )
}

...但是当执行此任务时,它始终设置为logLevel in run in Compile := Level.Warn logLevel := Level.Warn logLevel in mainRunner := Level.Warn logLevel in streams := Level.Warn

scala logging sbt task log-level
1个回答
1
投票

不知道你的问题在哪里,但这个Info内容可以正常设置任务的日志级别

build.sbt

其中val mainRunner = taskKey[Unit]("Print some log") val runner2 = taskKey[DummyRun]("hold dummy runner") lazy val root = project .in(file(".")) .settings( runner2 := new DummyRun, mainRunner := { val logger = streams.value.log logger.warn("Hello warn") logger.info("Hello info") logger.debug("Hello debug") runner2.value.run(logger) }, (logLevel in mainRunner) := Level.Warn ) DummyRun文件夹中的一个内容

project

输出:

import sbt.Logger

class DummyRun {
  def run(log: Logger): Unit = {
    log.warn("DummyRun warn")
    log.info("DummyRun info")
    log.debug("DummyRun debug")
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.