【问题标题】:Logger uses same color for entire output记录器对整个输出使用相同的颜色
【发布时间】:2019-01-22 12:27:56
【问题描述】:

我正在尝试设置slf4j
当我简单地打印信息和错误时,我得到以下输出:

FATAL:   [http-thread-pool::http-listener-1(5)] INFO com.company.myclass - this is an information  
FATAL:   [http-thread-pool::http-listener-1(5)] ERROR com.company.myclass - this is an error

除了INFOERROR这两个字之外,还有相似之处,它们甚至有相同的颜色——红色。

这真的是我们想要的输出吗?
INFO 不应该有另一种颜色,以便可以将它们分开吗?

这是我的代码:

Logger log = LoggerFactory.getLogger(this.getClass());

log.info("this is an information");
log.error("this is an error");

我添加了这个 Maven 依赖项:SLF4J Simple Binding » 1.7.25

【问题讨论】:

  • 为什么两者都使用 FATAL 作为前缀?
  • 顺便说一句,我怀疑记录器正在使用任何颜色,更有可能这是 IDE 的一个功能(比如输出到固定错误总是红色,或者从 FATAL 开始时......)
  • @NAIT:我也不知道。
  • 我不使用netbeans,但任何菜单中都应该有一些设置或偏好...

标签: java logging netbeans slf4j


【解决方案1】:

您会收到红色消息,因为 slf4j-simple 默认使用 System.err 作为默认输出,而 logFile 未定义 private static String LOG_FILE_DEFAULT = "System.err"; 您可以在 source code 上查看。

如果您希望您的消息以白色打印,您可以使用以下参数指定您的输出 -Dorg.slf4j.simpleLogger.logFile=System.out 在这种情况下,System.err 将被 System.out 替换。

如果您选择其他日志库(例如 Log4j)并提供配置文件,您会注意到日志也会以白色显示。

【讨论】:

    猜你喜欢
    • 2013-12-18
    • 1970-01-01
    • 1970-01-01
    • 2018-07-27
    • 2021-09-25
    • 1970-01-01
    • 1970-01-01
    • 2016-05-23
    相关资源
    最近更新 更多