how to use sbt/amm scala script on pipe operator?

167 views Asked by At

I want to deal with log output with scala script. Like this:
java -jar app.jar | log.sc or java -jar app.jar | amm log.sc How to write a log.sc deal with app.jar print logs?

motivation

Replace java -jar app.jar > app.log with some smarter way to handle the output stream.
From now on, I want save the output stream to different file by days.

Thanks.

UPDATE

think of this example:

object Main extends App {
  var i = 0L
  while(true) {
    println("hello " + i)
    i += 1
  }
}

it assembly to a Loop.jar, how can I deal with printing log to file by date?

1

There are 1 answers

2
Aron T On

Why don't you put the call to java inside your Ammonite script.

val log = %%('java,"-jar","app.jar")

The log variable captures the output and you can have the script write it a named logged file.

You can see an example where I do something similar here. There is an included script from another repository where I create & name the log file.