8

What are the means of redirecting output from a single command to a file in sbt?

I could exit sbt, execute sbt mycommand > out.txt, and start it again, but I'm wondering if there's an alternative?

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487

1 Answers1

5

In Add a custom logger you can find more information about what's required to have a custom logger that logs to a file - use extraLoggers and add an instance of sbt.AbstractLogger that does the saving.

You may find my answer to Displaying timestamp for debug mode in SBT? useful. The example copied here:

def datedPrintln = (m: String) =>
  println(s"+++ ${java.util.Calendar.getInstance().getTime()} $m")

extraLoggers := {
  val clientLogger = FullLogger {
    new Logger {
      def log(level: Level.Value, message: => String): Unit =
        if(level >= Level.Info) datedPrintln(s"$message at $level")
      def success(message: => String): Unit = datedPrintln(s"success: $message")
      def trace(t: => Throwable): Unit = datedPrintln(s"trace: throwable: $t")
    }
  }
  val currentFunction = extraLoggers.value
  (key: ScopedKey[_]) => clientLogger +: currentFunction(key)
}
Community
  • 1
  • 1
Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420