How to redirect console output of command to a file?

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?


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)
}
链接地址: http://www.djcxy.com/p/80836.html

上一篇: 与格式的jquery datepicker问题

下一篇: 如何将命令的控制台输出重定向到文件?