java - 为什么 java.util.logging.Logger 打印到 stderr?

标签 java eclipse logging stderr java.util.logging

我有一个简单的设置来记录消息:JDK 8 Update 65Eclipse Mars

import java.util.logging.Logger;

public class Example {

    private final static Logger LOGGER = Logger.getLogger(Example.class.getName());

    public static void main(String[] args) {
        LOGGER.info("Test");
    }

}

我希望在 stdout 上得到输出, 就像使用 System.out.println(); .
而是它被打印在 stderr 上,这会导致在 eclipse 控制台上显示红色字体:

enter image description here

我知道我可以通过编写自定义 Handler 来改变这种行为, 但我想知道为什么默认输出出现在 stderr 上而不是 stdout

记录器应该使用 stdout对于 fine + info并使用 stderr对于 severe水平。

最佳答案

java.util.logging API是根据 JSR 47: Logging API Specification 开发的.根据“Proposed Final Draft”中的更改日志,ConsoleHandler 始终使用 System.err。 JCP 页面还列出了 API 的原始作者,我认为只有这些名字才能真正知道您问题的答案。

也就是说,我认为起源来自 System.err API 文档。

Typically this stream corresponds to display output or another output destination specified by the host environment or user. By convention, this output stream is used to display error messages or other information that should come to the immediate attention of a user even if the principal output stream, the value of the variable out, has been redirected to a file or other destination that is typically not continuously monitored.

反对System.out :

The "standard" output stream. This stream is already open and ready to accept output data. Typically this stream corresponds to display output or another output destination specified by the host environment or user.

记录映射到诊断而不是原始数据。将数据与诊断错误信息分开很重要,尤其是当管道处理在一起时,因为下游消费者只准备好接受数据信息而不是错误消息。参见 Confused about stdin, stdout and stderr?获取更多详细信息。

关于java - 为什么 java.util.logging.Logger 打印到 stderr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34156052/

相关文章:

java - 理解-XX :+PrintCompilation的输出

java - 如何使用虚线作为单元格边框?

Java 堆栈溢出错误 - 如何在 Eclipse 中增加堆栈大小?

Eclipse EGit |分支差异

c++ - 前置或附加到每个 printf 调用

java - RecyclerView 搜索过滤器过滤结果后位置错误

java - 什么是oop中的松耦合和紧耦合(java)

java - Tomcat 8 Apache Log4j 1.2.17 时间

java - 无法通过 OnClick 事件在 TextView 上切换我的可见性

elasticsearch - 使用 Kafka 作为 Filebeats 和 Logstash 的替代品