3

My sbt update is very slow, I'd like to see what happens in details.

So, I have:

sbt --debug update > sbtupdate.log

The problem is that the log does not have timestamp for each line, how to enable it?

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
anuni
  • 889
  • 10
  • 26

2 Answers2

4

To my knowledge, it is not possible with only SBT options. However this question provides a good solution. I will rephrase the answer for your specific case. All the following supposes a Unix OS but it should be possible to adapt it for a Windows environment (and straightforward if using Cygwin).

First, you need a script called for example predate.sh that contains:

#!/bin/bash
while read line ; do
    echo "$(date): ${line}"
done

The date command can be changed following your needs. Then, you must make this script executable with chmod u+x predate.sh.

Finally run your initial command and pipe the standard output to our new script:

sbt --debug update | ./predate.sh > sbtupdate.log

Please read the linked question, it contains interesting other responses.

Community
  • 1
  • 1
Lomig Mégard
  • 1,828
  • 14
  • 18
1

I think what you need is to develop a custom logger as described in Add a custom logger:

The setting extraLoggers can be used to add custom loggers. A custom logger should implement [AbstractLogger]. extraLoggers is a function ScopedKey[_] => Seq[AbstractLogger]. This means that it can provide different logging based on the task that requests the logger.

In the custom logger you'd prepend messages with timestamp.

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)
}

You can find out about how to develop your own logger in my answer to Custom extraLogger not getting [success] messages in sbt?

Community
  • 1
  • 1
Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420