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

后端 未结 13 1481
旧巷少年郎
旧巷少年郎 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:37
    Handler consoleHandler = new Handler(){
             @Override
                public void publish(LogRecord record)
                {
                    if (getFormatter() == null)
                    {
                        setFormatter(new SimpleFormatter());
                    }
    
                    try {
                        String message = getFormatter().format(record);
                        if (record.getLevel().intValue() >= Level.WARNING.intValue())
                        {
                            System.err.write(message.getBytes());                       
                        }
                        else
                        {
                            System.out.write(message.getBytes());
                        }
                    } catch (Exception exception) {
                        reportError(null, exception, ErrorManager.FORMAT_FAILURE);
                    }
    
                }
    
                @Override
                public void close() throws SecurityException {}
                @Override
                public void flush(){}
            };
    
    0 讨论(0)
提交回复
热议问题