Copy and Redirecting System.err Stream

前端 未结 1 1257
忘掉有多难
忘掉有多难 2021-01-26 13:15

I am currently using java.util.logger in my application. It sends its output to System.err. I need it to continue to do this, but I also need to send that output to something el

1条回答
  •  清酒与你
    2021-01-26 13:53

    As always when note people referencing java.util.logger I feel inclined to at least recommend looking at another logging library, such as logback and slf4j.

    This blog post describes a method which can easily be adapted to support what you're asking for. In short what you need to do is define a PrintStream which can duplicate its output, assign this using:

    System.setErr(doubleLoggingPrintStream)
    

    0 讨论(0)
提交回复
热议问题