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?

1 Answer 1

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.

2
  • 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? Sep 3, 2017 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
    – Aron T
    Sep 3, 2017 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.