Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sbt: suppressing logging prefix in stdout

Tags:

logging

scala

sbt

When using sbt with forking (fork in run := true), every output from my application to stdout is prefixed by [info]; output to stderr is prefixed with [error].

This behavior is somewhat annoying when using a Java logging framework which outputs to stderr. The resulting debug messages typically look like this:

[error] [main] INFO MyClass ...
[error] [main] DEBUG MyClass ...

I would like to suppress these prefixes like when running the code without forking. What I tried:

  • setting sbt -Dsbt.log.noformat=true in the sbt launch script. But this only removes colored ANSI output; prefixes are still there just without color
  • setting logLevel in run := Level.Error in build.sbt. This does not seem to have any influence on logging with forking.

Is there any way to suppress the prefixes?

like image 611
bluenote10 Avatar asked Jan 24 '13 15:01

bluenote10


1 Answers

You need to set the output strategy of your project.

In my extended build I have the following settings:

settings = Project.defaultSettings ++ Seq(
  fork                  :=   true, // Fork to separate process
  connectInput in run   :=   true, // Connects stdin to sbt during forked runs
  outputStrategy        :=   Some(StdoutOutput) // Get rid of output prefix
  // ... other settings
)
like image 195
Andy Avatar answered Oct 02 '22 21:10

Andy