0

So I have a library that I am using in my project that uses System.out for logging and I want all of my logging to be standardized in the play logger (play.Logger). So, I was wondering if there is a way of redirecting the System.out to the Play Logger say at the debug level? Maybe by changing System.out to use a different stream?

Notes:

My Play logger is configured to use the following appenders:

ch.qos.logback.core.ConsoleAppender
ch.qos.logback.core.FileAppender

I think the library only calls System.out.println(String)

sazzy4o
  • 3,073
  • 6
  • 34
  • 62

1 Answers1

0

Use following snippet:

    System.setOut(new PrintStream(new OutputStream() {
        StringBuilder sb = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            if (b == '\n') {
                writeStringToActualLogger(sb.toString());
                sb = new StringBuilder();
            } else {
                sb.append((char) b);
            }
        }
    }));

Keep in mind that it only works with ASCII.

You have to implement writeStringToActualLogger to write string to your logger.

talex
  • 17,973
  • 3
  • 29
  • 66