How do you set logLevel
when using streams.value.log
in an SBT task?
For instance, how can this task's logs be supressed to just Warn
logs?:
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()
)
}
Inside and outside the task I've tried various logLevel settings, like:
logLevel in run in Compile := Level.Warn
logLevel := Level.Warn
logLevel in mainRunner := Level.Warn
logLevel in streams := Level.Warn
...but it always is set to Info
when this task executes
Not sure where your problem is but this build.sbt
content works fine with setting log level for a task
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
)
Where DummyRun
is a class in project
folder with content
import sbt.Logger
class DummyRun {
def run(log: Logger): Unit = {
log.warn("DummyRun warn")
log.info("DummyRun info")
log.debug("DummyRun debug")
}
}
Outputs:
> mainRunner
[warn] Hello warn
[warn] DummyRun warn