0

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?

LoranceChen
  • 2,453
  • 2
  • 22
  • 48

1 Answers1

0

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.

Aron T
  • 108
  • 6
  • `app.jar` is a massive web project. `val log` shouldn't hold the result in memory.It seems caused a `java.lang.OutOfMemoryError` exception.Could you write some example? – LoranceChen Sep 03 '17 at 10:27
  • The way I understood it originally is that you wanted to capture the terminal output when you launch the app, which is what I was suggesting above. But from your example you have this app which is doing quite a bit of output which you want to capture. It seems to me, Ammonite isn't what you want. This sounds like a classic logging use case, and you should investigate the many good options for handling logging in Java/Scala like slf4j with for example this [Scala wrapper](https://github.com/typesafehub/scala-logging) – Aron T Sep 03 '17 at 17:51