How do I change java logging console output from std err to std out?

后端 未结 13 1622
旧巷少年郎
旧巷少年郎 2020-11-27 06:50

I\'m using the standard ConsoleHandler from java.util.logging and by default the console output is directed to the error stream (i.e. System.

13条回答
  •  时光说笑
    2020-11-27 07:19

    Hmm I just got bit in the foot a few times, trying to accomplish this feat. Before googling my way here I managed to conjure the following hack. Ugly, but it seems to get the job done.

    public class StdoutConsoleHandler extends ConsoleHandler {
      protected void setOutputStream(OutputStream out) throws SecurityException {
        super.setOutputStream(System.out); // kitten killed here :-(
      }
    }
    

    Watch out: Calling setOutputStream() from the constructor is tempting, but it does (as Jon Skeet already pointed out) close System.err. Mad skills!

提交回复
热议问题